Living Conditions and Dropout

Consolidate the database


We generated the database with the new requested variables. Must note that this database already filtererd minors at admission but people that did not reported a valid age (remember differences with Stata).


Show code
invisible("84,936 x 254 # 2020-10-25")
invisible("84,944 x 277 # 2020-12-20")

prueba<-
CONS_C1_df_dup_SEP_2020 %>% 
dplyr::group_by(hash_key) %>% 
  dplyr::mutate(menor_edad=dplyr::case_when(edad_al_ing<18~1,TRUE~0),menor_edad=sum(menor_edad,na.rm=T)) %>% 
  dplyr::ungroup() %>% 
  dplyr::filter(edad_al_ing>=18| is.na(edad_al_ing)) %>%  #Sólo así llegamos a 109,642 casos, igual que en STATA
  
  dplyr::group_by(hash_key) %>% 
  dplyr::mutate(dup2=row_number()) %>% 
  dplyr::mutate(duplicates_filtered2=n()) %>% 
  
  dplyr::mutate(max_cum_dias_trat_sin_na=max(cum_dias_trat_sin_na, na.rm=T)) %>% 
  dplyr::mutate(max_cum_diff_bet_treat=max(cum_diff_bet_treat, na.rm=T)) %>% 
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
#Formatear días de tratamiento y diferencia en días excliyendo a los casos a los que le borramos un tratamiento menor a 18.
#local vars `" "diff_bet_treat_" "dias_treat_imp_sin_na_" "cum_diff_bet_treat_" "cum_dias_trat_sin_na_" "mean_cum_dias_trat_sin_na_" "mean_cum_diff_bet_treat_" "'   
  dplyr::ungroup() %>% 
  dplyr::filter(dup2==1) %>%   #84,936 x 254 # 2020-10-25, 
  dplyr::mutate(cum_dias_trat_sin_na_1= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_2,TRUE~cum_dias_trat_sin_na_1)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_2= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_3,TRUE~cum_dias_trat_sin_na_2)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_3= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_4,TRUE~cum_dias_trat_sin_na_3)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_4= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_5,TRUE~cum_dias_trat_sin_na_4)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_5= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_6,TRUE~cum_dias_trat_sin_na_5)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_6= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_7,TRUE~cum_dias_trat_sin_na_6)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_7= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_8,TRUE~cum_dias_trat_sin_na_7)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_8= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_9,TRUE~cum_dias_trat_sin_na_8)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_9= dplyr::case_when(menor_edad>0~cum_dias_trat_sin_na_10,TRUE~cum_dias_trat_sin_na_9)) %>% 
  dplyr::mutate(cum_dias_trat_sin_na_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~cum_dias_trat_sin_na_10)) %>% 
  
  dplyr::mutate(cum_diff_bet_treat_1= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_2,TRUE~cum_diff_bet_treat_1)) %>% 
  dplyr::mutate(cum_diff_bet_treat_2= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_3,TRUE~cum_diff_bet_treat_2)) %>% 
  dplyr::mutate(cum_diff_bet_treat_3= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_4,TRUE~cum_diff_bet_treat_3)) %>% 
  dplyr::mutate(cum_diff_bet_treat_4= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_5,TRUE~cum_diff_bet_treat_4)) %>% 
  dplyr::mutate(cum_diff_bet_treat_5= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_6,TRUE~cum_diff_bet_treat_5)) %>% 
  dplyr::mutate(cum_diff_bet_treat_6= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_7,TRUE~cum_diff_bet_treat_6)) %>% 
  dplyr::mutate(cum_diff_bet_treat_7= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_8,TRUE~cum_diff_bet_treat_7)) %>% 
  dplyr::mutate(cum_diff_bet_treat_8= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_9,TRUE~cum_diff_bet_treat_8)) %>% 
  dplyr::mutate(cum_diff_bet_treat_9= dplyr::case_when(menor_edad>0~cum_diff_bet_treat_10,TRUE~cum_diff_bet_treat_9)) %>% 
  dplyr::mutate(cum_diff_bet_treat_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~cum_diff_bet_treat_10)) %>%
  
  dplyr::mutate(tipo_de_plan_2_1= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_2),TRUE~as.character(tipo_de_plan_2_1))) %>% 
  dplyr::mutate(tipo_de_plan_2_2= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_3),TRUE~as.character(tipo_de_plan_2_2))) %>% 
  dplyr::mutate(tipo_de_plan_2_3= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_4),TRUE~as.character(tipo_de_plan_2_3))) %>% 
  dplyr::mutate(tipo_de_plan_2_4= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_5),TRUE~as.character(tipo_de_plan_2_4))) %>% 
  dplyr::mutate(tipo_de_plan_2_5= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_6),TRUE~as.character(tipo_de_plan_2_5))) %>% 
  dplyr::mutate(tipo_de_plan_2_6= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_7),TRUE~as.character(tipo_de_plan_2_6))) %>% 
  dplyr::mutate(tipo_de_plan_2_7= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_8),TRUE~as.character(tipo_de_plan_2_7))) %>% 
  dplyr::mutate(tipo_de_plan_2_8= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_9),TRUE~as.character(tipo_de_plan_2_8))) %>% 
  dplyr::mutate(tipo_de_plan_2_9= dplyr::case_when(menor_edad>0~as.character(tipo_de_plan_2_10),TRUE~as.character(tipo_de_plan_2_9))) %>% 
  dplyr::mutate(tipo_de_plan_2_10= dplyr::case_when(menor_edad>0~NA_character_,TRUE~as.character(tipo_de_plan_2_10))) %>%
  
  dplyr::mutate(motivodeegreso_mod_imp_1= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_2),TRUE~as.character(motivodeegreso_mod_imp_1))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_2= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_3),TRUE~as.character(motivodeegreso_mod_imp_2))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_3= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_4),TRUE~as.character(motivodeegreso_mod_imp_3))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_4= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_5),TRUE~as.character(motivodeegreso_mod_imp_4))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_5= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_6),TRUE~as.character(motivodeegreso_mod_imp_5))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_6= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_7),TRUE~as.character(motivodeegreso_mod_imp_6))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_7= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_8),TRUE~as.character(motivodeegreso_mod_imp_7))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_8= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_9),TRUE~as.character(motivodeegreso_mod_imp_8))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_9= dplyr::case_when(menor_edad>0~as.character(motivodeegreso_mod_imp_10),TRUE~as.character(motivodeegreso_mod_imp_9))) %>% 
  dplyr::mutate(motivodeegreso_mod_imp_10= dplyr::case_when(menor_edad>0~NA_character_,TRUE~as.character(motivodeegreso_mod_imp_10))) %>%
  
  dplyr::mutate(mean_cum_dias_trat_sin_na_1= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_2,TRUE~mean_cum_dias_trat_sin_na_1)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_2= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_3,TRUE~mean_cum_dias_trat_sin_na_2)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_3= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_4,TRUE~mean_cum_dias_trat_sin_na_3)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_4= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_5,TRUE~mean_cum_dias_trat_sin_na_4)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_5= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_6,TRUE~mean_cum_dias_trat_sin_na_5)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_6= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_7,TRUE~mean_cum_dias_trat_sin_na_6)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_7= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_8,TRUE~mean_cum_dias_trat_sin_na_7)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_8= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_9,TRUE~mean_cum_dias_trat_sin_na_8)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_9= dplyr::case_when(menor_edad>0~mean_cum_dias_trat_sin_na_10,TRUE~mean_cum_dias_trat_sin_na_9)) %>% 
  dplyr::mutate(mean_cum_dias_trat_sin_na_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~mean_cum_dias_trat_sin_na_10)) %>%
    
  dplyr::mutate(mean_cum_diff_bet_treat_1= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_2,TRUE~mean_cum_diff_bet_treat_1)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_2= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_3,TRUE~mean_cum_diff_bet_treat_2)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_3= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_4,TRUE~mean_cum_diff_bet_treat_3)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_4= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_5,TRUE~mean_cum_diff_bet_treat_4)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_5= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_6,TRUE~mean_cum_diff_bet_treat_5)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_6= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_7,TRUE~mean_cum_diff_bet_treat_6)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_7= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_8,TRUE~mean_cum_diff_bet_treat_7)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_8= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_9,TRUE~mean_cum_diff_bet_treat_8)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_9= dplyr::case_when(menor_edad>0~mean_cum_diff_bet_treat_10,TRUE~mean_cum_diff_bet_treat_9)) %>% 
  dplyr::mutate(mean_cum_diff_bet_treat_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~mean_cum_diff_bet_treat_10)) %>%
    
  dplyr::mutate(diff_bet_treat_1= dplyr::case_when(menor_edad>0~diff_bet_treat_2,TRUE~diff_bet_treat_1)) %>% 
  dplyr::mutate(diff_bet_treat_2= dplyr::case_when(menor_edad>0~diff_bet_treat_3,TRUE~diff_bet_treat_2)) %>% 
  dplyr::mutate(diff_bet_treat_3= dplyr::case_when(menor_edad>0~diff_bet_treat_4,TRUE~diff_bet_treat_3)) %>% 
  dplyr::mutate(diff_bet_treat_4= dplyr::case_when(menor_edad>0~diff_bet_treat_5,TRUE~diff_bet_treat_4)) %>% 
  dplyr::mutate(diff_bet_treat_5= dplyr::case_when(menor_edad>0~diff_bet_treat_6,TRUE~diff_bet_treat_5)) %>% 
  dplyr::mutate(diff_bet_treat_6= dplyr::case_when(menor_edad>0~diff_bet_treat_7,TRUE~diff_bet_treat_6)) %>% 
  dplyr::mutate(diff_bet_treat_7= dplyr::case_when(menor_edad>0~diff_bet_treat_8,TRUE~diff_bet_treat_7)) %>% 
  dplyr::mutate(diff_bet_treat_8= dplyr::case_when(menor_edad>0~diff_bet_treat_9,TRUE~diff_bet_treat_8)) %>% 
  dplyr::mutate(diff_bet_treat_9= dplyr::case_when(menor_edad>0~diff_bet_treat_10,TRUE~diff_bet_treat_9)) %>% 
  dplyr::mutate(diff_bet_treat_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~diff_bet_treat_10)) %>%
      
  dplyr::mutate(dias_treat_imp_sin_na_1= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_2,TRUE~dias_treat_imp_sin_na_1)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_2= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_3,TRUE~dias_treat_imp_sin_na_2)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_3= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_4,TRUE~dias_treat_imp_sin_na_3)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_4= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_5,TRUE~dias_treat_imp_sin_na_4)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_5= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_6,TRUE~dias_treat_imp_sin_na_5)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_6= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_7,TRUE~dias_treat_imp_sin_na_6)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_7= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_8,TRUE~dias_treat_imp_sin_na_7)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_8= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_9,TRUE~dias_treat_imp_sin_na_8)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_9= dplyr::case_when(menor_edad>0~dias_treat_imp_sin_na_10,TRUE~dias_treat_imp_sin_na_9)) %>% 
  dplyr::mutate(dias_treat_imp_sin_na_10= dplyr::case_when(menor_edad>0~NA_real_,TRUE~dias_treat_imp_sin_na_10)) %>%

# diff y dias treat  
  dplyr::mutate(dias_treat_imp_sin_na_four = rowMeans(dplyr::select(., dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10), na.rm=T)) %>% #,na.rm=F
  
  dplyr::mutate(diff_bet_treat_four = rowMeans(dplyr::select(., diff_bet_treat_4, diff_bet_treat_5, diff_bet_treat_6, diff_bet_treat_7, diff_bet_treat_8, diff_bet_treat_9, diff_bet_treat_10), na.rm=T)) %>% #,na.rm=F
# cum
  dplyr::mutate(cum_dias_trat_sin_na_four = rowMeans(dplyr::select(., cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10), na.rm=T)) %>% #,na.rm=F
  
  dplyr::mutate(cum_diff_bet_treat_four = rowMeans(dplyr::select(., cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10), na.rm=T)) %>% #,na.rm=F
# mean cum
  dplyr::mutate(mean_cum_dias_trat_sin_na_four = rowMeans(dplyr::select(., mean_cum_dias_trat_sin_na_4, mean_cum_dias_trat_sin_na_5, mean_cum_dias_trat_sin_na_6, mean_cum_dias_trat_sin_na_7, mean_cum_dias_trat_sin_na_8, mean_cum_dias_trat_sin_na_9, mean_cum_dias_trat_sin_na_10), na.rm=T)) %>% #,na.rm=F
  
  dplyr::mutate(mean_cum_diff_bet_treat_four = rowMeans(dplyr::select(., mean_cum_diff_bet_treat_4, mean_cum_diff_bet_treat_5, mean_cum_diff_bet_treat_6, mean_cum_diff_bet_treat_7, mean_cum_diff_bet_treat_8, mean_cum_diff_bet_treat_9, mean_cum_diff_bet_treat_10), na.rm=T)) %>% #,na.rm=F
  # tipo de plana
  dplyr::mutate(tipo_de_plan_2_mod=dplyr::case_when(grepl("PAB",tipo_de_plan_2)~"PAB",
                                                    grepl("PAI",tipo_de_plan_2)~"PAI",
                                                    grepl("PR",tipo_de_plan_2)~"PR",
                                                    TRUE~NA_character_)) %>% 
  dplyr::mutate(tipo_de_plan_2_mod=factor(tipo_de_plan_2_mod)) %>% 
  dplyr::mutate(estatus_ocupacional= dplyr::case_when(!is.na(cat_ocupacional)&!is.na(estatus_ocupacional)~"Empleado",
                                                      TRUE~as.character(estatus_ocupacional)))%>% 
  dplyr::mutate(estatus_ocupacional= as.factor(estatus_ocupacional))%>% 
  dplyr::mutate(cnt_mod_cie_10_dg_cons_sus_or= dplyr::case_when(as.character(dg_trs_cons_sus_or)=="Drug dependence"~dg_total_cie_10+1,
                                                    TRUE~dg_total_cie_10))%>% 
  dplyr::mutate(freq_cons_sus_prin= dplyr::case_when(as.character(freq_cons_sus_prin)=="Did not use"~"Less than 1 day a week",
                                                     TRUE~as.character(freq_cons_sus_prin)))%>% 
  dplyr::mutate(freq_cons_sus_prin= as.factor(freq_cons_sus_prin)) %>% 
  #edad más 65
  dplyr::mutate(mas_65= dplyr::case_when(edad_al_ing>65~1,
                                                     TRUE~0))%>% 
  dplyr::mutate(mas_65= as.factor(mas_65)) %>% 
  dplyr::mutate(comorbidity_icd_10=dplyr::case_when(dg_total_cie_10>=2~ "Two or more",
                                                    dg_total_cie_10==1~ "One",
                                                    as.character(dg_cie_10_rec)=="Diagnosis unknown (under study)"~"Diagnosis unknown (under study)",
                                                    as.character(dg_cie_10_rec)=="Without psychiatric comorbidity"~"Without psychiatric comorbidity")) %>%
  dplyr::mutate(comorbidity_icd_10=as.factor(comorbidity_icd_10)) %>% 
 # dplyr::select(-menor_edad) %>% 
  dplyr::mutate(no_group=1) %>% 
  dplyr::mutate(had_readm=dplyr::case_when(duplicates_filtered2>1~1,
                                           TRUE~0)) %>% 
  dplyr::mutate(n_treats=factor(dplyr::case_when(duplicates_filtered2>3~"04 or more",
                                duplicates_filtered2==3~"03",
                                duplicates_filtered2==2~"02",
                                duplicates_filtered2==1~"01"))) 

Time for this code chunk to run: 0.3 minutes


Updated in 2021 June & August

We only left users in treatments in General Population (PG) and missing values and discarded under 18 years (n= 84,944). Additionally, we recategorized the variable ‘Living with’ (con_quien_vive).


Show code
#janitor::tabyl(CONS_C1_df_dup_SEP_2020$otros_probl_at_sm_or)
#round(prop.table(table(CONS_C1_df_dup_SEP_2020$otros_probl_at_sm_or)),3)
#With      With                 Other Alone  With            With  
#relatives couple and children               children only   couple only
#38105        21806             7275   8026   3191           6540 

library(readr)
prueba2<-
prueba %>% 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
  #AUG 2021: 
  dplyr::mutate(con_quien_vive_joel=dplyr::case_when(
    grepl("Solo$",con_quien_vive, ignore.case=T)~"Alone",
    
    grepl("Con abuelos",con_quien_vive, ignore.case=T)~"Family of origin",
    grepl("Con hermanos",con_quien_vive, ignore.case=T)~"Family of origin",
    grepl("Con la madre \\(sola\\)",con_quien_vive, ignore.case=T)~"Family of origin",
    grepl("Con otro pariente",con_quien_vive, ignore.case=T)~"Others",
    grepl("con hijos y padres o familia",con_quien_vive, ignore.case=T)~"Family of origin",
    grepl("con la pareja y padres o familia de origen",con_quien_vive, ignore.case=T)~"With couple/children",
    grepl("con padres o familia de origen",con_quien_vive, ignore.case=T)~"Family of origin",
    #2021-10-01
    grepl("Únicamente con hijos",con_quien_vive, ignore.case=T)~"With couple/children",
    
    grepl("Únicamente con pareja",con_quien_vive, ignore.case=T)~"With couple/children",
    #2021-10-01
    grepl("Con la Pareja, Hijos y Padres o Familia de Origen",con_quien_vive, ignore.case=T)~"With couple/children",
    
    grepl("Hijos y Padres o Familia de Origen",con_quien_vive, ignore.case=T)~"Family of origin",
    #2021-10-01
    grepl("Únicamente con la pareja e hijos",con_quien_vive, ignore.case=T)~"With couple/children",

    grepl("Con amigos",con_quien_vive, ignore.case=T)~"Others",
    grepl("Con otro NO pariente",con_quien_vive, ignore.case=T)~"Others",
    grepl("*Otros$",con_quien_vive, ignore.case=T)~"Others")) %>% 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
    #janitor::tabyl(con_quien_vive, con_quien_vive_rec)
    dplyr::filter(!grepl("M-",tipo_de_plan_2)) %>% 
    #janitor::tabyl(embarazo)
    #No    Si  <NA> 
    #76081   496    89 
    #prueba2 %>% janitor::tabyl(embarazo,tiene_menores_de_edad_a_cargo)
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
  dplyr::mutate(numero_de_hijos_mod_joel=dplyr::case_when(
    grepl("Si$",embarazo, ignore.case=T)~as.integer(numero_de_hijos_mod+1),
    T~as.integer(numero_de_hijos_mod)))%>% 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
    dplyr::filter(edad_al_ing_grupos=="18-29") %>% 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
    dplyr::mutate(dom_violence=factor(dplyr::case_when(
      grepl("Violencia Intrafamiliar$",otros_probl_at_sm_or, ignore.case=T)~1,
      is.na(otros_probl_at_sm_or)~NA_real_,
      T~0),levels=c(0,1),labels=c("No domestic violence","Domestic violence"))) %>% 
    dplyr::mutate(sex_abuse=factor(dplyr::case_when(
      grepl("Abuso Sexual",otros_probl_at_sm_or, ignore.case=T)~1,
      is.na(otros_probl_at_sm_or)~NA_real_,
      T~0),levels=c(0,1),labels=c("No sexual abuse","Sexual abuse"))) %>% 
  dplyr::filter(!grepl("Others",con_quien_vive_joel)) %>% 
#5 de agosto, paso de 26,236 a 23,979, descartando 2,257 casos que tienen "otros".
  #:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
  #TENENCIA VIVIENDA
  #Allegado, Arrienda, Cedida, Ocupación Irregular, Otros, Paga dividendo, Propia
#vive transitoriamente en casa ajena
  dplyr::mutate(tenencia_de_la_vivienda_mod=
                  factor(dplyr::case_when(tenencia_de_la_vivienda_mod=="Allegado"~"Stays temporarily with a relative",
                                 tenencia_de_la_vivienda_mod=="Arrienda"~"Renting",
                                 tenencia_de_la_vivienda_mod=="Cedida"~"Owner/Transferred dwellings/Pays Dividends",
                                 tenencia_de_la_vivienda_mod=="Ocupación Irregular"~"Illegal Settlement",
                                 tenencia_de_la_vivienda_mod=="Otros"~"Others",
                                 tenencia_de_la_vivienda_mod=="Paga dividendo"~"Owner/Transferred dwellings/Pays Dividends",
                                 tenencia_de_la_vivienda_mod=="Propia"~"Owner/Transferred dwellings/Pays Dividends",
                                 T~NA_character_))) %>% 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:   
#:#:#:#:#:#:#:#:#:#DAR ESTRUCTURA ORDINAL#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
  dplyr::mutate(escolaridad_rec=parse_factor(as.character(escolaridad_rec),levels=c('3-Completed primary school or less', '2-Completed high school or less', '1-More than high school'), ordered =T,trim_ws=T,include_na =F, locale=locale(encoding = "Latin1"))) %>%  
  dplyr::mutate(freq_cons_sus_prin=parse_factor(as.character(freq_cons_sus_prin),levels=c('Less than 1 day a week','2 to 3 days a week','4 to 6 days a week','1 day a week or more','Daily'), ordered =T,trim_ws=F,include_na =F)) %>% #, locale=locale(encoding = "Latin1")
  dplyr::mutate(compromiso_biopsicosocial=parse_factor(as.character(compromiso_biopsicosocial),levels=c('1-Mild', '2-Moderate','3-Severe'), ordered =T,trim_ws=F,include_na =F)) %>% #, locale=locale(encoding = "Latin1")
    dplyr::mutate(comorbidity_icd_10=parse_factor(as.character(comorbidity_icd_10),levels=c('Without psychiatric comorbidity', 'Diagnosis unknown (under study)','One','Two or more'), ordered =T,trim_ws=F,include_na =F)) %>% #, locale=locale(encoding = "Latin1")
    dplyr::mutate(cnt_mod_cie_10_or=parse_factor(as.character(cnt_mod_cie_10_or),levels=c('0', '1','2','3'), ordered =T,trim_ws=F,include_na =F)) %>%   #, locale=locale(encoding = "Latin1")
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#dplyr::mutate(edad_al_ing_grupos=if_else(edad_al_ing_grupos=='18-29','<18-29',as.character(edad_al_ing_grupos),NA_character_)) %>%
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#FRECUENCIA CONSUMO: Regroup 1 día a la semana y No usó en el último mes
dplyr::mutate(freq_cons_sus_prin=if_else(freq_cons_sus_prin=='Did not use','Less than 1 day a week',as.character(freq_cons_sus_prin),NA_character_)) 
#"escolaridad_rec", "freq_cons_sus_prin", "num_otras_sus_mod", "numero_de_hijos_mod_joel", "cnt_mod_cie_10_or", "comorbidity_icd_10", "compromiso_biopsicosocial"    
  
  
#numero_de_hijos_mod #Número de Hijos (Valor Max.)/Number of Children (Max. Value)
#hijos_trat_res #Tiene Hijos en Ingreso a Tratamiento Residencial del Último Registro/Have Children in Residential Treatment of the Last Entry
#prueba2 %>% janitor::tabyl(numero_de_hijos_mod,embarazo)     
#prueba2 %>% janitor::tabyl(numero_de_hijos_mod,hijos_trat_res) #me parece que está bien, no hay contradicciones
#prueba2 %>% janitor::tabyl(con_quien_vive,con_quien_vive_joel)
#prueba2 %>% janitor::tabyl(con_quien_vive,con_quien_vive_joel) %>% copiar_nombres()

#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:

Time for this code chunk to run: 0 minutes


We ended having 23,979 users.

In the data base for 2021, only includes general population or mixed-gender programs at baseline. The variable whether the respondent had children at admission to a residential treatment had many missing values (16%). In the cases that is feasible to have children, it shows 3% of missing values.

Must note that there are patients that may respond that they have children in treatment and respond that they have more than a child. But there can be people that did not report children and having children in residential treatments.



Total

Show code
#browse hash_key duplicates_filtered2 cum_diff_bet_treat dup2_real diff_bet_treat if hash_key=="0737aacbb7efdd418f7a37ce3386ce5e"|hash_key=="07668f2d3e4f6beb7975e43ee96eac80"

#diff_bet_treat_five+ cum_dias_trat_sin_na_five+ cum_diff_bet_treat_five+
#    mean_cum_dias_trat_sin_na_five+ mean_cum_diff_bet_treat_five,

attr(prueba$n_treats,"label") <- "No. of treatments with 18+ at admission between 2010 and 2019"
attr(prueba$comorbidity_icd_10,"label") <- "Comorbidity ICD-10 (with amount of different diagnosis)"
attr(prueba$dias_treat_imp_sin_na_four,"label") <- "Days of Treatment (Fourth or those that follow)"
attr(prueba$diff_bet_treat_four,"label") <- "Days of Difference Between Treatments (Fifth treatment or those that folow)"
attr(prueba$cum_dias_trat_sin_na_four,"label") <- "Cumulative Days of Treatment (Fourth or those that follow)"
attr(prueba$cum_diff_bet_treat_four,"label") <- "Cumulative Difference Between Treatments (Fifth or those that follow)" #hash_key 
attr(prueba$mean_cum_dias_trat_sin_na_four,"label") <- "Average Cumulative Days of Treatment (Fourth or those that follow)"
attr(prueba$mean_cum_diff_bet_treat_four,"label") <- "Average Cumulative Difference Between Treatments (Fifth or those that follow)"
attr(prueba$cnt_mod_cie_10_dg_cons_sus_or,"label") <- "Total count of Psychiatric & Drug dependence Diagnostics"
attr(prueba$max_cum_diff_bet_treat,"label") <- "Max. Cumulative Difference Between Treatments"
attr(prueba$max_cum_dias_trat_sin_na,"label") <- "Max. Cumulative Days of Treatment"
attr(prueba$tipo_de_plan_2_mod,"label") <- "Type of Plan (Independently of the Program)"
attr(prueba$condicion_ocupacional_corr,"label") <- 'Occupational Status Corrected(f)'
attr(prueba$cat_ocupacional_corr,"label") <- 'Occupational Category Corrected(f)'
attr(prueba$compromiso_biopsicosocial,"label") <- 'Biopsychosocial Compromise'
attr(prueba$tenencia_de_la_vivienda_mod,"label") <- 'Tenure status of households'
#attr(prueba$,"label")<-"Starting Substance"
attr(prueba$sus_principal_mod,"label")<-"Starting Substance"

attr(prueba$cum_dias_trat_sin_na_1,"label") <- "Cum. Days of Treatment (1st Treatment)"
attr(prueba$cum_dias_trat_sin_na_2,"label") <- "Cum. Days of Treatment (2nd Treatment)"
attr(prueba$cum_dias_trat_sin_na_3,"label") <- "Cum. Days of Treatment (3rd Treatment)"
attr(prueba$cum_dias_trat_sin_na_4,"label") <- "Cum. Days of Treatment (4th Treatment)"
attr(prueba$cum_dias_trat_sin_na_5,"label") <- "Cum. Days of Treatment (5th Treatment)"
attr(prueba$cum_dias_trat_sin_na_6,"label") <- "Cum. Days of Treatment (6th Treatment)"
attr(prueba$cum_dias_trat_sin_na_7,"label") <- "Cum. Days of Treatment (7th Treatment)"
attr(prueba$cum_dias_trat_sin_na_8,"label") <- "Cum. Days of Treatment (8th Treatment)"
attr(prueba$cum_dias_trat_sin_na_9,"label") <- "Cum. Days of Treatment (9th Treatment)"
attr(prueba$cum_dias_trat_sin_na_10,"label") <-"Cum. Days of Treatment (10th Treatment)"
attr(prueba$cum_diff_bet_treat_1,"label") <- "Cum. Diff Between Treatments (1st Treatment)"
attr(prueba$cum_diff_bet_treat_2,"label") <- "Cum. Diff Between Treatments (2nd Treatment)"
attr(prueba$cum_diff_bet_treat_3,"label") <- "Cum. Diff Between Treatments (3rd Treatment)"
attr(prueba$cum_diff_bet_treat_4,"label") <- "Cum. Diff Between Treatments (4th Treatment)"
attr(prueba$cum_diff_bet_treat_5,"label") <- "Cum. Diff Between Treatments (5th Treatment)"
attr(prueba$cum_diff_bet_treat_6,"label") <- "Cum. Diff Between Treatments (6th Treatment)"
attr(prueba$cum_diff_bet_treat_7,"label") <- "Cum. Diff Between Treatments (7th Treatment)"
attr(prueba$cum_diff_bet_treat_8,"label") <- "Cum. Diff Between Treatments (8th Treatment)"
attr(prueba$cum_diff_bet_treat_9,"label") <- "Cum. Diff Between Treatments (9th Treatment)"
attr(prueba$cum_diff_bet_treat_10,"label") <-"Cum. Diff Between Treatments (10th Treatment)"

attr(prueba2$n_treats,"label") <- "No. of treatments with 18+ at admission between 2010 and 2019"
attr(prueba2$comorbidity_icd_10,"label") <- "Comorbidity ICD-10 (with amount of different diagnosis)"
attr(prueba2$dias_treat_imp_sin_na_four,"label") <- "Days of Treatment (Fourth or those that follow)"
attr(prueba2$diff_bet_treat_four,"label") <- "Days of Difference Between Treatments (Fifth treatment or those that folow)"
attr(prueba2$cum_dias_trat_sin_na_four,"label") <- "Cumulative Days of Treatment (Fourth or those that follow)"
attr(prueba2$cum_diff_bet_treat_four,"label") <- "Cumulative Difference Between Treatments (Fifth or those that follow)" #hash_key 
attr(prueba2$mean_cum_dias_trat_sin_na_four,"label") <- "Average Cumulative Days of Treatment (Fourth or those that follow)"
attr(prueba2$mean_cum_diff_bet_treat_four,"label") <- "Average Cumulative Difference Between Treatments (Fifth or those that follow)"
attr(prueba2$cnt_mod_cie_10_dg_cons_sus_or,"label") <- "Total count of Psychiatric & Drug dependence Diagnostics"
attr(prueba2$max_cum_diff_bet_treat,"label") <- "Max. Cumulative Difference Between Treatments"
attr(prueba2$max_cum_dias_trat_sin_na,"label") <- "Max. Cumulative Days of Treatment"
attr(prueba2$tipo_de_plan_2_mod,"label") <- "Type of Plan (Independently of the Program)"
attr(prueba2$condicion_ocupacional_corr,"label") <- 'Occupational Status Corrected(f)'
attr(prueba2$cat_ocupacional_corr,"label") <- 'Occupational Category Corrected(f)'
attr(prueba2$con_quien_vive_joel,"label") <- 'Whom you live with(cohabitation status) (Recoded) (f)'
attr(prueba2$compromiso_biopsicosocial,"label") <- 'Biopsychosocial Compromise'
attr(prueba2$tenencia_de_la_vivienda_mod,"label") <- 'Tenure status of households'
attr(prueba2$sus_ini_mod_mvv,"label")<-"Starting Substance"

attr(prueba2$cum_dias_trat_sin_na_1,"label") <- "Cum. Days of Treatment (1st Treatment)"
attr(prueba2$cum_dias_trat_sin_na_2,"label") <- "Cum. Days of Treatment (2nd Treatment)"
attr(prueba2$cum_dias_trat_sin_na_3,"label") <- "Cum. Days of Treatment (3rd Treatment)"
attr(prueba2$cum_dias_trat_sin_na_4,"label") <- "Cum. Days of Treatment (4th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_5,"label") <- "Cum. Days of Treatment (5th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_6,"label") <- "Cum. Days of Treatment (6th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_7,"label") <- "Cum. Days of Treatment (7th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_8,"label") <- "Cum. Days of Treatment (8th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_9,"label") <- "Cum. Days of Treatment (9th Treatment)"
attr(prueba2$cum_dias_trat_sin_na_10,"label") <-"Cum. Days of Treatment (10th Treatment)"

attr(prueba2$dias_treat_imp_sin_na_1,"label") <- "Days of Treatment (1st Treatment)"
attr(prueba2$dias_treat_imp_sin_na_2,"label") <- "Days of Treatment (2nd Treatment)"
attr(prueba2$dias_treat_imp_sin_na_3,"label") <- "Days of Treatment (3rd Treatment)"
attr(prueba2$dias_treat_imp_sin_na_4,"label") <- "Days of Treatment (4th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_5,"label") <- "Days of Treatment (5th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_6,"label") <- "Days of Treatment (6th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_7,"label") <- "Days of Treatment (7th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_8,"label") <- "Days of Treatment (8th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_9,"label") <- "Days of Treatment (9th Treatment)"
attr(prueba2$dias_treat_imp_sin_na_10,"label") <-"Days of Treatment (10th Treatment)"

attr(prueba2$cum_diff_bet_treat_1,"label") <- "Cum. Diff Between Treatments (1st Treatment)"
attr(prueba2$cum_diff_bet_treat_2,"label") <- "Cum. Diff Between Treatments (2nd Treatment)"
attr(prueba2$cum_diff_bet_treat_3,"label") <- "Cum. Diff Between Treatments (3rd Treatment)"
attr(prueba2$cum_diff_bet_treat_4,"label") <- "Cum. Diff Between Treatments (4th Treatment)"
attr(prueba2$cum_diff_bet_treat_5,"label") <- "Cum. Diff Between Treatments (5th Treatment)"
attr(prueba2$cum_diff_bet_treat_6,"label") <- "Cum. Diff Between Treatments (6th Treatment)"
attr(prueba2$cum_diff_bet_treat_7,"label") <- "Cum. Diff Between Treatments (7th Treatment)"
attr(prueba2$cum_diff_bet_treat_8,"label") <- "Cum. Diff Between Treatments (8th Treatment)"
attr(prueba2$cum_diff_bet_treat_9,"label") <- "Cum. Diff Between Treatments (9th Treatment)"
attr(prueba2$cum_diff_bet_treat_10,"label") <-"Cum. Diff Between Treatments (10th Treatment)"
attr(prueba2$numero_de_hijos_mod_joel,"label") <-"Number of Children (Max. Value), adding 1 if pregnant at admission"
attr(prueba2$sex_abuse,"label") <-"Sexual abuse"
attr(prueba2$dom_violence,"label") <-"Domestic violence"
attr(prueba2$freq_cons_sus_prin,"label") <-"Frequency of drug use in the primary substance"

#n_treats mean_cum_diff_bet_treat_four mean_cum_diff_bet_treat_four cum_diff_bet_treat_four cum_dias_trat_sin_na_four diff_bet_treat_four dias_treat_imp_sin_na_four cnt_mod_cie_10_dg_cons_sus_or max_cum_diff_bet_treat max_cum_dias_trat_sin_na cum_diff_bet_treat_10 cum_dias_trat_sin_na_10 tipo_de_plan_2_mod


library(compareGroups)
table3 <- compareGroups::compareGroups(no_group ~ sexo_2+ escolaridad_rec+ estado_conyugal_2+ compromiso_biopsicosocial+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ con_quien_vive_joel+ numero_de_hijos_mod_joel+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+ tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+ cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+ max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+ dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(sexo_2=3,
                                                 escolaridad_rec=3,
                                                 estado_conyugal_2=3,
                                                 compromiso_biopsicosocial=2,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 con_quien_vive_joel=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2, 
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered= 3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 2,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence = 3
                                                 ),
                                       data = prueba2,
                                       include.miss = T,
                                       var.equal=T
                                       
)#cie_10 cat_ocupacional estatus_ocupacional

pvals <- getResults(table3)
#p.adjust(pvals, method = "BH")
restab3 <- createTable(table3,show.p.overall = F)
compareGroups::export2md(restab3, size=9, first.strip=T, hide.no="no", position="center",col.names=c("Variables","Total"),
                         format="html",caption= "Summary descriptives table")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 1: Summary descriptives table
Variables Total
N=23979
Sexo Usuario/Sex of User:
Men 19850 (82.8%)
Women 4129 (17.2%)
escolaridad_rec:
3-Completed primary school or less 5634 (23.5%)
2-Completed high school or less 14518 (60.5%)
1-More than high school 3751 (15.6%)
‘Missing’ 76 (0.32%)
Estado Conyugal/Marital Status:
Married/Shared living arrangements 5127 (21.4%)
Separated/Divorced 501 (2.09%)
Single 18294 (76.3%)
Widower 30 (0.13%)
‘Missing’ 27 (0.11%)
Biopsychosocial Compromise:
1-Mild 2240 (9.34%)
2-Moderate 13949 (58.2%)
3-Severe 7352 (30.7%)
‘Missing’ 438 (1.83%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 15.0 [13.0;16.0]
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 25.4 [22.6;27.7]
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent):
Alcohol 10341 (43.1%)
Cocaine hydrochloride 934 (3.90%)
Cocaine paste 1054 (4.40%)
Marijuana 9165 (38.2%)
Other 411 (1.71%)
‘Missing’ 2074 (8.65%)
Starting Substance:
Alcohol 10182 (42.5%)
Cocaine hydrochloride 970 (4.05%)
Marijuana 9255 (38.6%)
Other 398 (1.66%)
Cocaine paste 1100 (4.59%)
‘Missing’ 2074 (8.65%)
Frequency of drug use in the primary substance:
1 day a week or more 1616 (6.74%)
2 to 3 days a week 7059 (29.4%)
4 to 6 days a week 4105 (17.1%)
Daily 9911 (41.3%)
Less than 1 day a week 1166 (4.86%)
‘Missing’ 122 (0.51%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f):
Smoked or Pulmonary Aspiration 13902 (58.0%)
Intranasal (powder aspiration) 5575 (23.2%)
Injected Intravenously or Intramuscularly 16 (0.07%)
Oral (drunk or eaten) 4470 (18.6%)
Other 12 (0.05%)
‘Missing’ 4 (0.02%)
Whom you live with(cohabitation status) (Recoded) (f):
Alone 1335 (5.57%)
Family of origin 15455 (64.5%)
With couple/children 7189 (30.0%)
Number of Children (Max. Value), adding 1 if pregnant at admission 1.00 [0.00;1.00]
Occupational Status Corrected(f):
Employed 10423 (43.5%)
Inactive 2019 (8.42%)
Looking for a job for the first time 97 (0.40%)
No activity 1333 (5.56%)
Not seeking for work 216 (0.90%)
Unemployed 9891 (41.2%)
Occupational Category Corrected(f):
Employer 322 (1.34%)
Other 222 (0.93%)
Salaried 7039 (29.4%)
Self-employed 1934 (8.07%)
Unpaid family labour 65 (0.27%)
Volunteer worker 39 (0.16%)
‘Missing’ 14358 (59.9%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months):
Mayor o igual a 90 días 17383 (72.5%)
Menos de 90 días 6596 (27.5%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded):
Without psychiatric comorbidity 9259 (38.6%)
Diagnosis unknown (under study) 5198 (21.7%)
With psychiatric comorbidity 9522 (39.7%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 147 [84.0;254]
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00]
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00]
Type of Plan (Independently of the Program):
PAB 9277 (38.7%)
PAI 11390 (47.5%)
PR 3286 (13.7%)
‘Missing’ 26 (0.11%)
Tenure status of households:
Illegal Settlement 191 (0.80%)
Others 562 (2.34%)
Owner/Transferred dwellings/Pays Dividends 7502 (31.3%)
Renting 3872 (16.1%)
Stays temporarily with a relative 10646 (44.4%)
‘Missing’ 1206 (5.03%)
Cum. Days of Treatment (1st Treatment) 147 [84.0;254]
Cum. Days of Treatment (2nd Treatment) 318 [207;489]
Cum. Days of Treatment (3rd Treatment) 485 [335;704]
Cum. Days of Treatment (4th Treatment) 638 [433;897]
Cum. Days of Treatment (5th Treatment) 805 [550;1041]
Cum. Days of Treatment (6th Treatment) 944 [716;1152]
Cum. Days of Treatment (7th Treatment) 1076 [888;1279]
Cum. Days of Treatment (8th Treatment) 1192 [1152;1232]
Cum. Days of Treatment (9th Treatment) 1403 [1403;1403]
Cum. Days of Treatment (10th Treatment) 1622 [1622;1622]
Days of Treatment (1st Treatment) 147 [84.0;254]
Days of Treatment (2nd Treatment) 137 [77.0;239]
Days of Treatment (3rd Treatment) 134 [73.0;237]
Days of Treatment (4th Treatment) 126 [70.0;224]
Days of Treatment (5th Treatment) 143 [67.0;260]
Days of Treatment (6th Treatment) 145 [76.8;199]
Days of Treatment (7th Treatment) 120 [23.0;175]
Days of Treatment (8th Treatment) 40.0 [29.5;84.5]
Days of Treatment (9th Treatment) 211 [211;211]
Days of Treatment (10th Treatment) 219 [219;219]
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00]
Cum. Diff Between Treatments (2nd Treatment) 801 [405;1390]
Cum. Diff Between Treatments (3rd Treatment) 1155 [686;1680]
Cum. Diff Between Treatments (4th Treatment) 1341 [886;1972]
Cum. Diff Between Treatments (5th Treatment) 1458 [1047;1970]
Cum. Diff Between Treatments (6th Treatment) 1509 [1160;2294]
Cum. Diff Between Treatments (7th Treatment) 1188 [1184;1422]
Cum. Diff Between Treatments (8th Treatment) 1706 [1706;1706]
Cum. Diff Between Treatments (9th Treatment) 1944 [1944;1944]
Cum. Diff Between Treatments (10th Treatment) .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total):
1 18472 (77.0%)
2 3908 (16.3%)
3 1087 (4.53%)
4 347 (1.45%)
5 111 (0.46%)
6 37 (0.15%)
7 14 (0.06%)
8 2 (0.01%)
10 1 (0.00%)
Max. Cumulative Days of Treatment 182 [98.0;332]
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00]
Total count of Psychiatric & Drug dependence Diagnostics 1.00 [1.00;2.00]
cnt_mod_cie_10_or:
0 9259 (38.6%)
1 14314 (59.7%)
2 365 (1.52%)
3 41 (0.17%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses):
0 14457 (60.3%)
1 9116 (38.0%)
2 365 (1.52%)
3 41 (0.17%)
Days of Treatment (Fourth or those that follow) 138 [78.8;227]
Days of Difference Between Treatments (Fifth treatment or those that folow) 277 [140;485]
Cumulative Days of Treatment (Fourth or those that follow) 692 [460;936]
Cumulative Difference Between Treatments (Fifth or those that follow) 1412 [1031;1995]
Average Cumulative Days of Treatment (Fourth or those that follow) 163 [110;221]
Average Cumulative Difference Between Treatments (Fifth or those that follow) 340 [236;488]
Comorbidity ICD-10 (with amount of different diagnosis):
Without psychiatric comorbidity 9259 (38.6%)
Diagnosis unknown (under study) 5198 (21.7%)
One 9116 (38.0%)
Two or more 406 (1.69%)
No. of treatments with 18+ at admission between 2010 and 2019:
01 18475 (77.0%)
02 3907 (16.3%)
03 1085 (4.52%)
04 or more 512 (2.14%)
Sexual abuse:
No sexual abuse 18880 (78.7%)
Sexual abuse 289 (1.21%)
‘Missing’ 4810 (20.1%)
Domestic violence:
No domestic violence 14304 (59.7%)
Domestic violence 4865 (20.3%)
‘Missing’ 4810 (20.1%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)

Time for this code chunk to run: 0.1 minutes


Primary substance

Show code
table4 <- compareGroups::compareGroups(sus_principal_mod ~ sexo_2+ escolaridad_rec+ compromiso_biopsicosocial+ estado_conyugal_2+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ con_quien_vive_joel+ numero_de_hijos_mod_joel+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+ tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+ cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+ max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+ dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(
                                                 sexo_2=3,
                                                 escolaridad_rec=3,
                                                 compromiso_biopsicosocial=2,
                                                 estado_conyugal_2=3,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 con_quien_vive_joel=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2,                                                  
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered=3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 3,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence= 3
                                       ),
                                       data = prueba2,
                                       include.miss = T,
                                       var.equal=T
)#cie_10 cat_ocupacional estatus_ocupacional

pvals <- getResults(table4)
#p.adjust(pvals, method = "BH")
restab4 <- createTable(table4, show.p.overall = T)
compareGroups::export2md(restab4, size=9, first.strip=T, hide.no="no", position="center",
                         format="html",caption= "Summary descriptives by Primary Substance at Admission")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 2: Summary descriptives by Primary Substance at Admission
Alcohol Cocaine hydrochloride Marijuana Other Cocaine paste p.overall
N=4142 N=5394 N=2872 N=295 N=11276
Sexo Usuario/Sex of User: <0.001
Men 3321 (80.2%) 4474 (82.9%) 2356 (82.0%) 223 (75.6%) 9476 (84.0%)
Women 821 (19.8%) 920 (17.1%) 516 (18.0%) 72 (24.4%) 1800 (16.0%)
escolaridad_rec: .
3-Completed primary school or less 900 (21.7%) 873 (16.2%) 536 (18.7%) 62 (21.0%) 3263 (28.9%)
2-Completed high school or less 2376 (57.4%) 3441 (63.8%) 1714 (59.7%) 152 (51.5%) 6835 (60.6%)
1-More than high school 852 (20.6%) 1063 (19.7%) 614 (21.4%) 79 (26.8%) 1143 (10.1%)
‘Missing’ 14 (0.34%) 17 (0.32%) 8 (0.28%) 2 (0.68%) 35 (0.31%)
Biopsychosocial Compromise: <0.001
1-Mild 647 (15.6%) 538 (9.97%) 442 (15.4%) 19 (6.44%) 594 (5.27%)
2-Moderate 2601 (62.8%) 3339 (61.9%) 1795 (62.5%) 156 (52.9%) 6058 (53.7%)
3-Severe 814 (19.7%) 1406 (26.1%) 560 (19.5%) 115 (39.0%) 4457 (39.5%)
‘Missing’ 80 (1.93%) 111 (2.06%) 75 (2.61%) 5 (1.69%) 167 (1.48%)
Estado Conyugal/Marital Status: .
Married/Shared living arrangements 1019 (24.6%) 1350 (25.0%) 465 (16.2%) 36 (12.2%) 2257 (20.0%)
Separated/Divorced 108 (2.61%) 128 (2.37%) 48 (1.67%) 8 (2.71%) 209 (1.85%)
Single 3005 (72.5%) 3908 (72.5%) 2352 (81.9%) 250 (84.7%) 8779 (77.9%)
Widower 5 (0.12%) 3 (0.06%) 4 (0.14%) 1 (0.34%) 17 (0.15%)
‘Missing’ 5 (0.12%) 5 (0.09%) 3 (0.10%) 0 (0.00%) 14 (0.12%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 15.0 [13.0;16.0] 15.0 [13.0;16.0] 15.0 [13.0;16.0] 14.0 [13.0;16.0] 14.0 [13.0;16.0] <0.001
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 25.7 [23.1;27.9] 25.6 [23.0;27.8] 23.6 [21.2;26.5] 24.3 [21.1;27.8] 25.5 [22.8;27.8] <0.001
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent): 0.000
Alcohol 3256 (78.6%) 2366 (43.9%) 982 (34.2%) 79 (26.8%) 3658 (32.4%)
Cocaine hydrochloride 44 (1.06%) 604 (11.2%) 22 (0.77%) 4 (1.36%) 260 (2.31%)
Cocaine paste 28 (0.68%) 57 (1.06%) 32 (1.11%) 2 (0.68%) 935 (8.29%)
Marijuana 513 (12.4%) 1913 (35.5%) 1490 (51.9%) 121 (41.0%) 5128 (45.5%)
Other 43 (1.04%) 65 (1.21%) 41 (1.43%) 65 (22.0%) 197 (1.75%)
‘Missing’ 258 (6.23%) 389 (7.21%) 305 (10.6%) 24 (8.14%) 1098 (9.74%)
Starting Substance: .
Alcohol 3249 (78.4%) 2335 (43.3%) 973 (33.9%) 79 (26.8%) 3546 (31.4%)
Cocaine hydrochloride 45 (1.09%) 627 (11.6%) 24 (0.84%) 4 (1.36%) 270 (2.39%)
Marijuana 520 (12.6%) 1922 (35.6%) 1498 (52.2%) 121 (41.0%) 5194 (46.1%)
Other 41 (0.99%) 63 (1.17%) 39 (1.36%) 65 (22.0%) 190 (1.68%)
Cocaine paste 29 (0.70%) 58 (1.08%) 33 (1.15%) 2 (0.68%) 978 (8.67%)
‘Missing’ 258 (6.23%) 389 (7.21%) 305 (10.6%) 24 (8.14%) 1098 (9.74%)
Frequency of drug use in the primary substance: .
1 day a week or more 384 (9.27%) 502 (9.31%) 125 (4.35%) 14 (4.75%) 591 (5.24%)
2 to 3 days a week 1817 (43.9%) 1934 (35.9%) 639 (22.2%) 52 (17.6%) 2617 (23.2%)
4 to 6 days a week 758 (18.3%) 941 (17.4%) 416 (14.5%) 42 (14.2%) 1948 (17.3%)
Daily 964 (23.3%) 1630 (30.2%) 1579 (55.0%) 166 (56.3%) 5572 (49.4%)
Less than 1 day a week 196 (4.73%) 354 (6.56%) 99 (3.45%) 19 (6.44%) 498 (4.42%)
‘Missing’ 23 (0.56%) 33 (0.61%) 14 (0.49%) 2 (0.68%) 50 (0.44%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f): .
Smoked or Pulmonary Aspiration 0 (0.00%) 0 (0.00%) 2872 (100%) 34 (11.5%) 10996 (97.5%)
Intranasal (powder aspiration) 0 (0.00%) 5394 (100%) 0 (0.00%) 14 (4.75%) 167 (1.48%)
Injected Intravenously or Intramuscularly 0 (0.00%) 0 (0.00%) 0 (0.00%) 16 (5.42%) 0 (0.00%)
Oral (drunk or eaten) 4142 (100%) 0 (0.00%) 0 (0.00%) 225 (76.3%) 103 (0.91%)
Other 0 (0.00%) 0 (0.00%) 0 (0.00%) 5 (1.69%) 7 (0.06%)
‘Missing’ 0 (0.00%) 0 (0.00%) 0 (0.00%) 1 (0.34%) 3 (0.03%)
Whom you live with(cohabitation status) (Recoded) (f): <0.001
Alone 311 (7.51%) 199 (3.69%) 148 (5.15%) 16 (5.42%) 661 (5.86%)
Family of origin 2434 (58.8%) 3384 (62.7%) 2031 (70.7%) 222 (75.3%) 7384 (65.5%)
With couple/children 1397 (33.7%) 1811 (33.6%) 693 (24.1%) 57 (19.3%) 3231 (28.7%)
Number of Children (Max. Value), adding 1 if pregnant at admission 1.00 [0.00;1.00] 1.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] 1.00 [0.00;2.00] <0.001
Occupational Status Corrected(f): .
Employed 2371 (57.2%) 2833 (52.5%) 1284 (44.7%) 96 (32.5%) 3839 (34.0%)
Inactive 410 (9.90%) 368 (6.82%) 418 (14.6%) 43 (14.6%) 780 (6.92%)
Looking for a job for the first time 16 (0.39%) 14 (0.26%) 22 (0.77%) 2 (0.68%) 43 (0.38%)
No activity 163 (3.94%) 226 (4.19%) 200 (6.96%) 27 (9.15%) 717 (6.36%)
Not seeking for work 20 (0.48%) 48 (0.89%) 24 (0.84%) 5 (1.69%) 119 (1.06%)
Unemployed 1162 (28.1%) 1905 (35.3%) 924 (32.2%) 122 (41.4%) 5778 (51.2%)
Occupational Category Corrected(f): .
Employer 88 (2.12%) 83 (1.54%) 34 (1.18%) 2 (0.68%) 115 (1.02%)
Other 48 (1.16%) 46 (0.85%) 30 (1.04%) 4 (1.36%) 94 (0.83%)
Salaried 1618 (39.1%) 1929 (35.8%) 878 (30.6%) 50 (16.9%) 2564 (22.7%)
Self-employed 399 (9.63%) 559 (10.4%) 217 (7.56%) 23 (7.80%) 736 (6.53%)
Unpaid family labour 5 (0.12%) 16 (0.30%) 11 (0.38%) 0 (0.00%) 33 (0.29%)
Volunteer worker 7 (0.17%) 8 (0.15%) 9 (0.31%) 1 (0.34%) 14 (0.12%)
‘Missing’ 1977 (47.7%) 2753 (51.0%) 1693 (58.9%) 215 (72.9%) 7720 (68.5%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months): <0.001
Mayor o igual a 90 días 3214 (77.6%) 3998 (74.1%) 2184 (76.0%) 221 (74.9%) 7766 (68.9%)
Menos de 90 días 928 (22.4%) 1396 (25.9%) 688 (24.0%) 74 (25.1%) 3510 (31.1%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded): <0.001
Without psychiatric comorbidity 1652 (39.9%) 2156 (40.0%) 1100 (38.3%) 75 (25.4%) 4276 (37.9%)
Diagnosis unknown (under study) 720 (17.4%) 1141 (21.2%) 568 (19.8%) 59 (20.0%) 2710 (24.0%)
With psychiatric comorbidity 1770 (42.7%) 2097 (38.9%) 1204 (41.9%) 161 (54.6%) 4290 (38.0%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 165 [96.0;281] 150 [87.0;251] 157 [91.0;274] 161 [89.0;298] 135 [75.8;240] <0.001
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.005
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] <0.001
Type of Plan (Independently of the Program): .
PAB 2120 (51.2%) 2321 (43.0%) 1380 (48.1%) 88 (29.8%) 3368 (29.9%)
PAI 1811 (43.7%) 2605 (48.3%) 1331 (46.3%) 175 (59.3%) 5468 (48.5%)
PR 208 (5.02%) 465 (8.62%) 157 (5.47%) 31 (10.5%) 2425 (21.5%)
‘Missing’ 3 (0.07%) 3 (0.06%) 4 (0.14%) 1 (0.34%) 15 (0.13%)
Tenure status of households: .
Illegal Settlement 18 (0.43%) 22 (0.41%) 22 (0.77%) 3 (1.02%) 126 (1.12%)
Others 88 (2.12%) 109 (2.02%) 90 (3.13%) 4 (1.36%) 271 (2.40%)
Owner/Transferred dwellings/Pays Dividends 1403 (33.9%) 1454 (27.0%) 945 (32.9%) 90 (30.5%) 3610 (32.0%)
Renting 821 (19.8%) 941 (17.4%) 445 (15.5%) 53 (18.0%) 1612 (14.3%)
Stays temporarily with a relative 1648 (39.8%) 2647 (49.1%) 1216 (42.3%) 135 (45.8%) 5000 (44.3%)
‘Missing’ 164 (3.96%) 221 (4.10%) 154 (5.36%) 10 (3.39%) 657 (5.83%)
Cum. Days of Treatment (1st Treatment) 165 [96.0;281] 150 [87.2;251] 157 [91.0;274] 161 [89.0;300] 135 [76.0;240] <0.001
Cum. Days of Treatment (2nd Treatment) 367 [235;577] 320 [212;491] 351 [239;520] 402 [288;592] 305 [196;468] <0.001
Cum. Days of Treatment (3rd Treatment) 550 [383;784] 483 [344;704] 500 [384;676] 600 [411;820] 473 [320;690] 0.013
Cum. Days of Treatment (4th Treatment) 810 [573;994] 659 [378;840] 595 [437;780] 913 [766;1162] 608 [432;874] 0.013
Cum. Days of Treatment (5th Treatment) 597 [430;972] 854 [506;1000] 866 [776;925] 2000 [2000;2000] 786 [554;1067] 0.364
Cum. Days of Treatment (6th Treatment) 1022 [669;1087] 803 [727;1080] 984 [940;995] 2230 [2230;2230] 949 [714;1175] 0.471
Cum. Days of Treatment (7th Treatment) 876 [778;975] 887 [581;957] 1348 [1348;1348] . [.;.] 1178 [1029;1300] 0.101
Cum. Days of Treatment (8th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1192 [1152;1232] .
Cum. Days of Treatment (9th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1403 [1403;1403] .
Cum. Days of Treatment (10th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1622 [1622;1622] .
Days of Treatment (1st Treatment) 165 [96.0;281] 150 [87.0;251] 157 [91.0;274] 161 [89.0;298] 135 [75.8;240] <0.001
Days of Treatment (2nd Treatment) 160 [92.0;278] 139 [79.0;241] 147 [80.2;262] 215 [106;307] 129 [72.0;224] <0.001
Days of Treatment (3rd Treatment) 135 [81.0;232] 140 [75.0;223] 138 [73.2;251] 108 [33.0;189] 133 [72.0;239] 0.881
Days of Treatment (4th Treatment) 152 [70.2;336] 124 [61.5;217] 128 [80.5;206] 75.0 [46.5;195] 124 [70.2;215] 0.505
Days of Treatment (5th Treatment) 182 [76.8;232] 151 [74.5;226] 330 [213;388] 588 [588;588] 141 [63.0;254] 0.268
Days of Treatment (6th Treatment) 67.0 [64.0;175] 85.0 [36.5;180] 144 [130;195] 230 [230;230] 154 [106;198] 0.373
Days of Treatment (7th Treatment) 31.0 [20.5;41.5] 175 [99.0;215] 364 [364;364] . [.;.] 120 [28.0;146] 0.223
Days of Treatment (8th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 40.0 [29.5;84.5] .
Days of Treatment (9th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 211 [211;211] .
Days of Treatment (10th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 219 [219;219] .
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;74.0] <0.001
Cum. Diff Between Treatments (2nd Treatment) 812 [413;1310] 799 [405;1420] 950 [533;1661] 947 [733;1511] 774 [392;1366] 0.120
Cum. Diff Between Treatments (3rd Treatment) 1075 [645;1639] 1221 [794;1732] 1209 [696;1821] 1274 [858;1290] 1146 [680;1667] 0.867
Cum. Diff Between Treatments (4th Treatment) 1424 [1098;2117] 1141 [888;2078] 1428 [1187;1640] 1398 [1398;1398] 1384 [880;1978] 0.971
Cum. Diff Between Treatments (5th Treatment) 1695 [960;1700] 1497 [1072;2131] 1446 [1432;1668] 1415 [1415;1415] 1470 [1062;1992] 0.992
Cum. Diff Between Treatments (6th Treatment) 1628 [1295;1961] 2411 [1953;2594] 1827 [1827;1827] . [.;.] 1287 [1088;1906] 0.452
Cum. Diff Between Treatments (7th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1188 [1184;1422] .
Cum. Diff Between Treatments (8th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1706 [1706;1706] .
Cum. Diff Between Treatments (9th Treatment) . [.;.] . [.;.] . [.;.] . [.;.] 1944 [1944;1944] .
Cum. Diff Between Treatments (10th Treatment) . . . . . .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total): .
1 3435 (82.9%) 4367 (81.0%) 2422 (84.3%) 246 (83.4%) 8002 (71.0%)
2 537 (13.0%) 781 (14.5%) 328 (11.4%) 35 (11.9%) 2227 (19.7%)
3 116 (2.80%) 176 (3.26%) 91 (3.17%) 11 (3.73%) 693 (6.15%)
4 46 (1.11%) 43 (0.80%) 25 (0.87%) 2 (0.68%) 231 (2.05%)
5 3 (0.07%) 17 (0.32%) 3 (0.10%) 0 (0.00%) 88 (0.78%)
6 3 (0.07%) 7 (0.13%) 2 (0.07%) 1 (0.34%) 24 (0.21%)
7 2 (0.05%) 3 (0.06%) 1 (0.03%) 0 (0.00%) 8 (0.07%)
8 0 (0.00%) 0 (0.00%) 0 (0.00%) 0 (0.00%) 2 (0.02%)
10 0 (0.00%) 0 (0.00%) 0 (0.00%) 0 (0.00%) 1 (0.01%)
Max. Cumulative Days of Treatment 194 [106;350] 181 [99.0;313] 182 [98.0;331] 200 [95.0;337] 179 [93.0;336] <0.001
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;123] <0.001
Total count of Psychiatric & Drug dependence Diagnostics: .
0 1108 (26.8%) 954 (17.7%) 719 (25.0%) 33 (11.2%) 1450 (12.9%)
1 1965 (47.4%) 2914 (54.0%) 1377 (47.9%) 138 (46.8%) 6303 (55.9%)
2 1003 (24.2%) 1438 (26.7%) 745 (25.9%) 115 (39.0%) 3376 (29.9%)
3 60 (1.45%) 75 (1.39%) 28 (0.97%) 9 (3.05%) 137 (1.21%)
4 6 (0.14%) 13 (0.24%) 3 (0.10%) 0 (0.00%) 10 (0.09%)
cnt_mod_cie_10_or: .
0 1652 (39.9%) 2156 (40.0%) 1100 (38.3%) 75 (25.4%) 4276 (37.9%)
1 2405 (58.1%) 3139 (58.2%) 1729 (60.2%) 207 (70.2%) 6834 (60.6%)
2 74 (1.79%) 84 (1.56%) 38 (1.32%) 13 (4.41%) 156 (1.38%)
3 11 (0.27%) 15 (0.28%) 5 (0.17%) 0 (0.00%) 10 (0.09%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses): .
0 2372 (57.3%) 3297 (61.1%) 1668 (58.1%) 134 (45.4%) 6986 (62.0%)
1 1685 (40.7%) 1998 (37.0%) 1161 (40.4%) 148 (50.2%) 4124 (36.6%)
2 74 (1.79%) 84 (1.56%) 38 (1.32%) 13 (4.41%) 156 (1.38%)
3 11 (0.27%) 15 (0.28%) 5 (0.17%) 0 (0.00%) 10 (0.09%)
Days of Treatment (Fourth or those that follow) 149 [74.8;322] 138 [74.0;218] 144 [99.0;218] 75.0 [46.5;226] 136 [79.1;223] 0.719
Days of Difference Between Treatments (Fifth treatment or those that folow) 308 [170;552] 340 [171;558] 330 [138;365] 70.5 [70.5;70.5] 256 [132;483] 0.695
Cumulative Days of Treatment (Fourth or those that follow) 831 [585;1012] 676 [412;902] 683 [499;809] 913 [766;1397] 684 [449;929] 0.047
Cumulative Difference Between Treatments (Fifth or those that follow) 1694 [1127;2134] 1370 [1032;2078] 1520 [1385;1640] 1406 [1406;1406] 1411 [1018;2019] 0.940
Average Cumulative Days of Treatment (Fourth or those that follow) 202 [144;248] 161 [98.3;201] 149 [125;192] 228 [191;302] 159 [108;217] 0.014
Average Cumulative Difference Between Treatments (Fifth or those that follow) 356 [272;518] 295 [241;493] 347 [296;407] 316 [316;316] 341 [228;483] 0.990
Comorbidity ICD-10 (with amount of different diagnosis): .
Without psychiatric comorbidity 1652 (39.9%) 2156 (40.0%) 1100 (38.3%) 75 (25.4%) 4276 (37.9%)
Diagnosis unknown (under study) 720 (17.4%) 1141 (21.2%) 568 (19.8%) 59 (20.0%) 2710 (24.0%)
One 1685 (40.7%) 1998 (37.0%) 1161 (40.4%) 148 (50.2%) 4124 (36.6%)
Two or more 85 (2.05%) 99 (1.84%) 43 (1.50%) 13 (4.41%) 166 (1.47%)
No. of treatments with 18+ at admission between 2010 and 2019: <0.001
01 3435 (82.9%) 4368 (81.0%) 2422 (84.3%) 246 (83.4%) 8004 (71.0%)
02 537 (13.0%) 781 (14.5%) 328 (11.4%) 36 (12.2%) 2225 (19.7%)
03 116 (2.80%) 175 (3.24%) 91 (3.17%) 10 (3.39%) 693 (6.15%)
04 or more 54 (1.30%) 70 (1.30%) 31 (1.08%) 3 (1.02%) 354 (3.14%)
Sexual abuse: .
No sexual abuse 3147 (76.0%) 4124 (76.5%) 2263 (78.8%) 227 (76.9%) 9119 (80.9%)
Sexual abuse 60 (1.45%) 65 (1.21%) 23 (0.80%) 6 (2.03%) 135 (1.20%)
‘Missing’ 935 (22.6%) 1205 (22.3%) 586 (20.4%) 62 (21.0%) 2022 (17.9%)
Domestic violence: <0.001
No domestic violence 2278 (55.0%) 3228 (59.8%) 1764 (61.4%) 161 (54.6%) 6873 (61.0%)
Domestic violence 929 (22.4%) 961 (17.8%) 522 (18.2%) 72 (24.4%) 2381 (21.1%)
‘Missing’ 935 (22.6%) 1205 (22.3%) 586 (20.4%) 62 (21.0%) 2022 (17.9%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)

Time for this code chunk to run: 0.2 minutes

Living with

Show code
table5 <- compareGroups::compareGroups(con_quien_vive_joel ~ sus_principal_mod+ sexo_2+ escolaridad_rec+ compromiso_biopsicosocial+ estado_conyugal_2+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ numero_de_hijos_mod_joel+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+  tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(sus_principal_mod=3,
                                                 sexo_2=3,
                                                 escolaridad_rec=3,
                                                 compromiso_biopsicosocial=2,
                                                 estado_conyugal_2=3,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2,                                                  
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered=3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 3,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence = 3
                                       ),
                                       data = prueba2,
                                       include.miss = T,
                                       var.equal=T,
                                       max.xlev = 10,
                                       max.ylev = 10
)#cie_10 cat_ocupacional estatus_ocupacional

pvals <- getResults(table5)
#p.adjust(pvals, method = "BH")
restab5 <- createTable(table5, show.p.overall = T)
compareGroups::export2md(restab5, size=9, first.strip=T, hide.no="no", position="center",col.names=c("Variables","Alone","Family of origin", "With couple", "P-value"),
                         format="html",caption= "Summary descriptives by With whom they live")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 3: Summary descriptives by With whom they live
Variables Alone Family of origin With couple P-value
N=1335 N=15455 N=7189
Sustancia Principal de Consumo (Sólo más frecuentes)(f)/Primary or Main Substance of Consumption at Admission (Only more frequent)(f): <0.001
Alcohol 311 (23.3%) 2434 (15.7%) 1397 (19.4%)
Cocaine hydrochloride 199 (14.9%) 3384 (21.9%) 1811 (25.2%)
Marijuana 148 (11.1%) 2031 (13.1%) 693 (9.64%)
Other 16 (1.20%) 222 (1.44%) 57 (0.79%)
Cocaine paste 661 (49.5%) 7384 (47.8%) 3231 (44.9%)
Sexo Usuario/Sex of User: <0.001
Men 1171 (87.7%) 13154 (85.1%) 5525 (76.9%)
Women 164 (12.3%) 2301 (14.9%) 1664 (23.1%)
escolaridad_rec: .
3-Completed primary school or less 359 (26.9%) 3333 (21.6%) 1942 (27.0%)
2-Completed high school or less 767 (57.5%) 9420 (61.0%) 4331 (60.2%)
1-More than high school 201 (15.1%) 2660 (17.2%) 890 (12.4%)
‘Missing’ 8 (0.60%) 42 (0.27%) 26 (0.36%)
Biopsychosocial Compromise: <0.001
1-Mild 92 (6.89%) 1328 (8.59%) 820 (11.4%)
2-Moderate 642 (48.1%) 8856 (57.3%) 4451 (61.9%)
3-Severe 588 (44.0%) 4988 (32.3%) 1776 (24.7%)
‘Missing’ 13 (0.97%) 283 (1.83%) 142 (1.98%)
Estado Conyugal/Marital Status: .
Married/Shared living arrangements 101 (7.57%) 858 (5.55%) 4168 (58.0%)
Separated/Divorced 55 (4.12%) 361 (2.34%) 85 (1.18%)
Single 1171 (87.7%) 14203 (91.9%) 2920 (40.6%)
Widower 1 (0.07%) 24 (0.16%) 5 (0.07%)
‘Missing’ 7 (0.52%) 9 (0.06%) 11 (0.15%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 14.0 [13.0;16.0] 15.0 [13.0;16.0] 15.0 [13.0;16.0] <0.001
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 26.3 [23.5;28.3] 24.7 [22.0;27.3] 26.4 [24.1;28.3] <0.001
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent): <0.001
Alcohol 587 (44.0%) 6505 (42.1%) 3249 (45.2%)
Cocaine hydrochloride 37 (2.77%) 548 (3.55%) 349 (4.85%)
Cocaine paste 68 (5.09%) 636 (4.12%) 350 (4.87%)
Marijuana 511 (38.3%) 6157 (39.8%) 2497 (34.7%)
Other 26 (1.95%) 250 (1.62%) 135 (1.88%)
‘Missing’ 106 (7.94%) 1359 (8.79%) 609 (8.47%)
Starting Substance: <0.001
Alcohol 581 (43.5%) 6385 (41.3%) 3216 (44.7%)
Cocaine hydrochloride 39 (2.92%) 571 (3.69%) 360 (5.01%)
Marijuana 514 (38.5%) 6228 (40.3%) 2513 (35.0%)
Other 24 (1.80%) 245 (1.59%) 129 (1.79%)
Cocaine paste 71 (5.32%) 667 (4.32%) 362 (5.04%)
‘Missing’ 106 (7.94%) 1359 (8.79%) 609 (8.47%)
Frequency of drug use in the primary substance: <0.001
1 day a week or more 55 (4.12%) 904 (5.85%) 657 (9.14%)
2 to 3 days a week 328 (24.6%) 4334 (28.0%) 2397 (33.3%)
4 to 6 days a week 204 (15.3%) 2737 (17.7%) 1164 (16.2%)
Daily 699 (52.4%) 6768 (43.8%) 2444 (34.0%)
Less than 1 day a week 45 (3.37%) 633 (4.10%) 488 (6.79%)
‘Missing’ 4 (0.30%) 79 (0.51%) 39 (0.54%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f): .
Smoked or Pulmonary Aspiration 798 (59.8%) 9266 (60.0%) 3838 (53.4%)
Intranasal (powder aspiration) 205 (15.4%) 3505 (22.7%) 1865 (25.9%)
Injected Intravenously or Intramuscularly 2 (0.15%) 12 (0.08%) 2 (0.03%)
Oral (drunk or eaten) 328 (24.6%) 2662 (17.2%) 1480 (20.6%)
Other 1 (0.07%) 7 (0.05%) 4 (0.06%)
‘Missing’ 1 (0.07%) 3 (0.02%) 0 (0.00%)
Number of Children (Max. Value), adding 1 if pregnant at admission 1.00 [0.00;1.00] 0.00 [0.00;1.00] 1.00 [1.00;2.00] 0.000
Occupational Status Corrected(f): <0.001
Employed 648 (48.5%) 5601 (36.2%) 4174 (58.1%)
Inactive 57 (4.27%) 1231 (7.97%) 731 (10.2%)
Looking for a job for the first time 3 (0.22%) 78 (0.50%) 16 (0.22%)
No activity 86 (6.44%) 1015 (6.57%) 232 (3.23%)
Not seeking for work 34 (2.55%) 154 (1.00%) 28 (0.39%)
Unemployed 507 (38.0%) 7376 (47.7%) 2008 (27.9%)
Occupational Category Corrected(f): .
Employer 14 (1.05%) 163 (1.05%) 145 (2.02%)
Other 17 (1.27%) 128 (0.83%) 77 (1.07%)
Salaried 432 (32.4%) 3833 (24.8%) 2774 (38.6%)
Self-employed 119 (8.91%) 953 (6.17%) 862 (12.0%)
Unpaid family labour 1 (0.07%) 52 (0.34%) 12 (0.17%)
Volunteer worker 2 (0.15%) 25 (0.16%) 12 (0.17%)
‘Missing’ 750 (56.2%) 10301 (66.7%) 3307 (46.0%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months): <0.001
Mayor o igual a 90 días 865 (64.8%) 11229 (72.7%) 5289 (73.6%)
Menos de 90 días 470 (35.2%) 4226 (27.3%) 1900 (26.4%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded): <0.001
Without psychiatric comorbidity 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
Diagnosis unknown (under study) 346 (25.9%) 3322 (21.5%) 1530 (21.3%)
With psychiatric comorbidity 536 (40.1%) 6415 (41.5%) 2571 (35.8%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 125 [68.0;223] 148 [84.0;257] 147 [86.0;253] <0.001
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.015
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] <0.001
Type of Plan (Independently of the Program): .
PAB 391 (29.3%) 5506 (35.6%) 3380 (47.0%)
PAI 586 (43.9%) 7508 (48.6%) 3296 (45.8%)
PR 356 (26.7%) 2423 (15.7%) 507 (7.05%)
‘Missing’ 2 (0.15%) 18 (0.12%) 6 (0.08%)
Tenure status of households: 0.000
Illegal Settlement 53 (3.97%) 48 (0.31%) 90 (1.25%)
Others 74 (5.54%) 374 (2.42%) 114 (1.59%)
Owner/Transferred dwellings/Pays Dividends 258 (19.3%) 5345 (34.6%) 1899 (26.4%)
Renting 555 (41.6%) 1154 (7.47%) 2163 (30.1%)
Stays temporarily with a relative 145 (10.9%) 7879 (51.0%) 2622 (36.5%)
‘Missing’ 250 (18.7%) 655 (4.24%) 301 (4.19%)
Cum. Days of Treatment (1st Treatment) 125 [68.0;224] 148 [84.0;257] 147 [86.0;253] <0.001
Cum. Days of Treatment (2nd Treatment) 285 [174;423] 320 [206;493] 326 [218;489] <0.001
Cum. Days of Treatment (3rd Treatment) 463 [260;644] 474 [326;700] 522 [361;730] 0.008
Cum. Days of Treatment (4th Treatment) 526 [339;755] 633 [426;878] 671 [486;941] 0.059
Cum. Days of Treatment (5th Treatment) 690 [532;1120] 798 [541;1047] 876 [576;1021] 0.604
Cum. Days of Treatment (6th Treatment) 460 [356;565] 897 [712;1153] 1006 [868;1144] 0.106
Cum. Days of Treatment (7th Treatment) 477 [376;578] 1165 [993;1331] 1076 [1074;1254] 0.100
Cum. Days of Treatment (8th Treatment) . [.;.] 1152 [1131;1172] 1273 [1273;1273] 0.221
Cum. Days of Treatment (9th Treatment) . [.;.] 1403 [1403;1403] . [.;.] .
Cum. Days of Treatment (10th Treatment) . [.;.] 1622 [1622;1622] . [.;.] .
Days of Treatment (1st Treatment) 125 [68.0;223] 148 [84.0;257] 147 [86.0;253] <0.001
Days of Treatment (2nd Treatment) 119 [57.0;204] 137 [76.0;239] 139 [83.0;245] <0.001
Days of Treatment (3rd Treatment) 127 [71.0;220] 127 [70.0;229] 148 [84.8;246] 0.020
Days of Treatment (4th Treatment) 143 [57.2;248] 125 [70.0;215] 131 [71.0;231] 0.997
Days of Treatment (5th Treatment) 199 [139;335] 138 [67.8;254] 145 [59.2;260] 0.567
Days of Treatment (6th Treatment) 28.0 [17.5;38.5] 149 [121;195] 116 [68.5;205] 0.121
Days of Treatment (7th Treatment) 16.5 [13.2;19.8] 169 [58.5;244] 53.0 [52.0;120] 0.075
Days of Treatment (8th Treatment) . [.;.] 84.5 [62.2;107] 19.0 [19.0;19.0] 0.221
Days of Treatment (9th Treatment) . [.;.] 211 [211;211] . [.;.] .
Days of Treatment (10th Treatment) . [.;.] 219 [219;219] . [.;.] .
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.812
Cum. Diff Between Treatments (2nd Treatment) 715 [380;1315] 779 [396;1355] 872 [441;1492] 0.075
Cum. Diff Between Treatments (3rd Treatment) 920 [405;1812] 1128 [674;1648] 1235 [770;1697] 0.436
Cum. Diff Between Treatments (4th Treatment) 1290 [1044;2121] 1196 [843;1722] 1448 [1149;2190] 0.034
Cum. Diff Between Treatments (5th Treatment) 2020 [1858;2182] 1470 [1091;1768] 1418 [944;2384] 0.513
Cum. Diff Between Treatments (6th Treatment) 2536 [2415;2657] 1576 [1244;2085] 1221 [1015;1287] 0.174
Cum. Diff Between Treatments (7th Treatment) . [.;.] 1418 [1300;1537] 1188 [1188;1188] 1.000
Cum. Diff Between Treatments (8th Treatment) . [.;.] 1706 [1706;1706] . [.;.] .
Cum. Diff Between Treatments (9th Treatment) . [.;.] 1944 [1944;1944] . [.;.] .
Cum. Diff Between Treatments (10th Treatment) . . . .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total): .
1 1033 (77.4%) 11903 (77.0%) 5536 (77.0%)
2 207 (15.5%) 2540 (16.4%) 1161 (16.1%)
3 71 (5.32%) 673 (4.35%) 343 (4.77%)
4 15 (1.12%) 233 (1.51%) 99 (1.38%)
5 7 (0.52%) 69 (0.45%) 35 (0.49%)
6 0 (0.00%) 27 (0.17%) 10 (0.14%)
7 2 (0.15%) 8 (0.05%) 4 (0.06%)
8 0 (0.00%) 1 (0.01%) 1 (0.01%)
10 0 (0.00%) 1 (0.01%) 0 (0.00%)
Max. Cumulative Days of Treatment 154 [80.0;304] 183 [98.0;332] 186 [100;338] <0.001
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.883
Total count of Psychiatric & Drug dependence Diagnostics: .
0 224 (16.8%) 2493 (16.1%) 1547 (21.5%)
1 695 (52.1%) 8175 (52.9%) 3827 (53.2%)
2 399 (29.9%) 4536 (29.3%) 1742 (24.2%)
3 16 (1.20%) 226 (1.46%) 67 (0.93%)
4 1 (0.07%) 25 (0.16%) 6 (0.08%)
cnt_mod_cie_10_or: .
0 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
1 860 (64.4%) 9441 (61.1%) 4013 (55.8%)
2 19 (1.42%) 264 (1.71%) 82 (1.14%)
3 3 (0.22%) 32 (0.21%) 6 (0.08%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses): .
0 799 (59.9%) 9040 (58.5%) 4618 (64.2%)
1 514 (38.5%) 6119 (39.6%) 2483 (34.5%)
2 19 (1.42%) 264 (1.71%) 82 (1.14%)
3 3 (0.22%) 32 (0.21%) 6 (0.08%)
Days of Treatment (Fourth or those that follow) 149 [51.8;234] 138 [77.8;225] 137 [85.4;236] 0.966
Days of Difference Between Treatments (Fifth treatment or those that folow) 464 [238;588] 258 [112;416] 288 [164;682] 0.064
Cumulative Days of Treatment (Fourth or those that follow) 590 [364;936] 683 [454;932] 727 [518;999] 0.083
Cumulative Difference Between Treatments (Fifth or those that follow) 1760 [1044;2121] 1345 [943;1759] 1518 [1174;2252] 0.081
Average Cumulative Days of Treatment (Fourth or those that follow) 133 [91.0;209] 162 [107;218] 171 [116;229] 0.080
Average Cumulative Difference Between Treatments (Fifth or those that follow) 348 [261;497] 312 [222;424] 373 [286;544] 0.064
Comorbidity ICD-10 (with amount of different diagnosis): <0.001
Without psychiatric comorbidity 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
Diagnosis unknown (under study) 346 (25.9%) 3322 (21.5%) 1530 (21.3%)
One 514 (38.5%) 6119 (39.6%) 2483 (34.5%)
Two or more 22 (1.65%) 296 (1.92%) 88 (1.22%)
No. of treatments with 18+ at admission between 2010 and 2019: 0.426
01 1034 (77.5%) 11905 (77.0%) 5536 (77.0%)
02 206 (15.4%) 2540 (16.4%) 1161 (16.1%)
03 71 (5.32%) 671 (4.34%) 343 (4.77%)
04 or more 24 (1.80%) 339 (2.19%) 149 (2.07%)
Sexual abuse: 0.034
No sexual abuse 1053 (78.9%) 12207 (79.0%) 5620 (78.2%)
Sexual abuse 27 (2.02%) 175 (1.13%) 87 (1.21%)
‘Missing’ 255 (19.1%) 3073 (19.9%) 1482 (20.6%)
Domestic violence: <0.001
No domestic violence 745 (55.8%) 9509 (61.5%) 4050 (56.3%)
Domestic violence 335 (25.1%) 2873 (18.6%) 1657 (23.0%)
‘Missing’ 255 (19.1%) 3073 (19.9%) 1482 (20.6%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)

Time for this code chunk to run: 0.1 minutes

Readmissions

Show code
table6 <- compareGroups::compareGroups(had_readm ~ sexo_2+ escolaridad_rec+ compromiso_biopsicosocial+ estado_conyugal_2+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ con_quien_vive_joel+ numero_de_hijos_mod_joel+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+ tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+ max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(
                                                 sexo_2=3,
                                                 escolaridad_rec=3,
                                                 compromiso_biopsicosocial=2,
                                                 estado_conyugal_2=3,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 con_quien_vive_joel=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2,                                                  
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered=3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 3,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence = 3
                                       ),
                                       data = prueba2,
                                       include.miss = T,
                                       var.equal=T
)#cie_10 cat_ocupacional estatus_ocupacional

pvals <- getResults(table6)
#p.adjust(pvals, method = "BH")
restab6 <- createTable(table6, show.p.overall = T)
compareGroups::export2md(restab6, size=9, first.strip=T, hide.no="no", position="center",col.names=c("Variables","Had no Readmissions","Had Readmissions", "P-value"),
                         format="html",caption= "Table 5. Summary descriptives by Readmissions")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
(#tab:tab_mas_8)Table 5. Summary descriptives by Readmissions
Variables Had no Readmissions Had Readmissions P-value
N=18475 N=5504
Sexo Usuario/Sex of User: 0.001
Men 15373 (83.2%) 4477 (81.3%)
Women 3102 (16.8%) 1027 (18.7%)
escolaridad_rec: <0.001
3-Completed primary school or less 4166 (22.5%) 1468 (26.7%)
2-Completed high school or less 11046 (59.8%) 3472 (63.1%)
1-More than high school 3202 (17.3%) 549 (9.97%)
‘Missing’ 61 (0.33%) 15 (0.27%)
Biopsychosocial Compromise: <0.001
1-Mild 1840 (9.96%) 400 (7.27%)
2-Moderate 11058 (59.9%) 2891 (52.5%)
3-Severe 5244 (28.4%) 2108 (38.3%)
‘Missing’ 333 (1.80%) 105 (1.91%)
Estado Conyugal/Marital Status: 0.105
Married/Shared living arrangements 3918 (21.2%) 1209 (22.0%)
Separated/Divorced 397 (2.15%) 104 (1.89%)
Single 14121 (76.4%) 4173 (75.8%)
Widower 18 (0.10%) 12 (0.22%)
‘Missing’ 21 (0.11%) 6 (0.11%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 15.0 [13.0;16.0] 14.0 [13.0;16.0] 0.088
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 25.3 [22.5;27.7] 25.5 [22.8;27.8] <0.001
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent): <0.001
Alcohol 7890 (42.7%) 2451 (44.5%)
Cocaine hydrochloride 688 (3.72%) 246 (4.47%)
Cocaine paste 667 (3.61%) 387 (7.03%)
Marijuana 6926 (37.5%) 2239 (40.7%)
Other 298 (1.61%) 113 (2.05%)
‘Missing’ 2006 (10.9%) 68 (1.24%)
Starting Substance: <0.001
Alcohol 7839 (42.4%) 2343 (42.6%)
Cocaine hydrochloride 703 (3.81%) 267 (4.85%)
Marijuana 6951 (37.6%) 2304 (41.9%)
Other 295 (1.60%) 103 (1.87%)
Cocaine paste 681 (3.69%) 419 (7.61%)
‘Missing’ 2006 (10.9%) 68 (1.24%)
Frequency of drug use in the primary substance: 0.003
1 day a week or more 1272 (6.88%) 344 (6.25%)
2 to 3 days a week 5493 (29.7%) 1566 (28.5%)
4 to 6 days a week 3140 (17.0%) 965 (17.5%)
Daily 7539 (40.8%) 2372 (43.1%)
Less than 1 day a week 935 (5.06%) 231 (4.20%)
‘Missing’ 96 (0.52%) 26 (0.47%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f): .
Smoked or Pulmonary Aspiration 10250 (55.5%) 3652 (66.4%)
Intranasal (powder aspiration) 4504 (24.4%) 1071 (19.5%)
Injected Intravenously or Intramuscularly 15 (0.08%) 1 (0.02%)
Oral (drunk or eaten) 3695 (20.0%) 775 (14.1%)
Other 7 (0.04%) 5 (0.09%)
‘Missing’ 4 (0.02%) 0 (0.00%)
Whom you live with(cohabitation status) (Recoded) (f): 0.935
Alone 1034 (5.60%) 301 (5.47%)
Family of origin 11905 (64.4%) 3550 (64.5%)
With couple/children 5536 (30.0%) 1653 (30.0%)
Number of Children (Max. Value), adding 1 if pregnant at admission 1.00 [0.00;1.00] 1.00 [0.00;2.00] <0.001
Occupational Status Corrected(f): <0.001
Employed 8278 (44.8%) 2145 (39.0%)
Inactive 1562 (8.45%) 457 (8.30%)
Looking for a job for the first time 72 (0.39%) 25 (0.45%)
No activity 1021 (5.53%) 312 (5.67%)
Not seeking for work 157 (0.85%) 59 (1.07%)
Unemployed 7385 (40.0%) 2506 (45.5%)
Occupational Category Corrected(f): <0.001
Employer 256 (1.39%) 66 (1.20%)
Other 176 (0.95%) 46 (0.84%)
Salaried 5527 (29.9%) 1512 (27.5%)
Self-employed 1584 (8.57%) 350 (6.36%)
Unpaid family labour 50 (0.27%) 15 (0.27%)
Volunteer worker 30 (0.16%) 9 (0.16%)
‘Missing’ 10852 (58.7%) 3506 (63.7%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months): 0.547
Mayor o igual a 90 días 13375 (72.4%) 4008 (72.8%)
Menos de 90 días 5100 (27.6%) 1496 (27.2%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded): 0.134
Without psychiatric comorbidity 7191 (38.9%) 2068 (37.6%)
Diagnosis unknown (under study) 4006 (21.7%) 1192 (21.7%)
With psychiatric comorbidity 7278 (39.4%) 2244 (40.8%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 146 [84.0;254] 148 [85.0;254] 0.399
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.949
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00] 0.00 [0.00;1.00] <0.001
Type of Plan (Independently of the Program): <0.001
PAB 7376 (39.9%) 1901 (34.5%)
PAI 8901 (48.2%) 2489 (45.2%)
PR 2184 (11.8%) 1102 (20.0%)
‘Missing’ 14 (0.08%) 12 (0.22%)
Tenure status of households: 0.056
Illegal Settlement 145 (0.78%) 46 (0.84%)
Others 424 (2.29%) 138 (2.51%)
Owner/Transferred dwellings/Pays Dividends 5782 (31.3%) 1720 (31.2%)
Renting 2999 (16.2%) 873 (15.9%)
Stays temporarily with a relative 8239 (44.6%) 2407 (43.7%)
‘Missing’ 886 (4.80%) 320 (5.81%)
Cum. Days of Treatment (1st Treatment) 146 [84.0;254] 148 [85.0;255] 0.380
Cum. Days of Treatment (2nd Treatment) . [.;.] 318 [207;489] .
Cum. Days of Treatment (3rd Treatment) . [.;.] 485 [335;704] .
Cum. Days of Treatment (4th Treatment) . [.;.] 638 [433;897] .
Cum. Days of Treatment (5th Treatment) . [.;.] 805 [550;1041] .
Cum. Days of Treatment (6th Treatment) . [.;.] 944 [716;1152] .
Cum. Days of Treatment (7th Treatment) . [.;.] 1076 [888;1279] .
Cum. Days of Treatment (8th Treatment) . [.;.] 1192 [1152;1232] .
Cum. Days of Treatment (9th Treatment) . [.;.] 1403 [1403;1403] .
Cum. Days of Treatment (10th Treatment) . [.;.] 1622 [1622;1622] .
Days of Treatment (1st Treatment) 146 [84.0;254] 148 [85.0;254] 0.399
Days of Treatment (2nd Treatment) . [.;.] 137 [77.0;239] .
Days of Treatment (3rd Treatment) . [.;.] 134 [73.0;237] .
Days of Treatment (4th Treatment) . [.;.] 126 [70.0;224] .
Days of Treatment (5th Treatment) . [.;.] 143 [67.0;260] .
Days of Treatment (6th Treatment) . [.;.] 145 [76.8;199] .
Days of Treatment (7th Treatment) . [.;.] 120 [23.0;175] .
Days of Treatment (8th Treatment) . [.;.] 40.0 [29.5;84.5] .
Days of Treatment (9th Treatment) . [.;.] 211 [211;211] .
Days of Treatment (10th Treatment) . [.;.] 219 [219;219] .
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00] 407 [149;926] 0.000
Cum. Diff Between Treatments (2nd Treatment) . [.;.] 801 [405;1390] .
Cum. Diff Between Treatments (3rd Treatment) . [.;.] 1155 [686;1680] .
Cum. Diff Between Treatments (4th Treatment) . [.;.] 1341 [886;1972] .
Cum. Diff Between Treatments (5th Treatment) . [.;.] 1458 [1047;1970] .
Cum. Diff Between Treatments (6th Treatment) . [.;.] 1509 [1160;2294] .
Cum. Diff Between Treatments (7th Treatment) . [.;.] 1188 [1184;1422] .
Cum. Diff Between Treatments (8th Treatment) . [.;.] 1706 [1706;1706] .
Cum. Diff Between Treatments (9th Treatment) . [.;.] 1944 [1944;1944] .
Cum. Diff Between Treatments (10th Treatment) . . .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total): .
1 18472 (100.0%) 0 (0.00%)
2 3 (0.02%) 3905 (70.9%)
3 0 (0.00%) 1087 (19.7%)
4 0 (0.00%) 347 (6.30%)
5 0 (0.00%) 111 (2.02%)
6 0 (0.00%) 37 (0.67%)
7 0 (0.00%) 14 (0.25%)
8 0 (0.00%) 2 (0.04%)
10 0 (0.00%) 1 (0.02%)
Max. Cumulative Days of Treatment 146 [84.0;254] 380 [239;583] 0.000
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00] 630 [232;1268] 0.000
Total count of Psychiatric & Drug dependence Diagnostics: <0.001
0 3463 (18.7%) 801 (14.6%)
1 9719 (52.6%) 2978 (54.1%)
2 5036 (27.3%) 1641 (29.8%)
3 232 (1.26%) 77 (1.40%)
4 25 (0.14%) 7 (0.13%)
cnt_mod_cie_10_or: 0.238
0 7191 (38.9%) 2068 (37.6%)
1 10972 (59.4%) 3342 (60.7%)
2 278 (1.50%) 87 (1.58%)
3 34 (0.18%) 7 (0.13%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses): 0.226
0 11197 (60.6%) 3260 (59.2%)
1 6966 (37.7%) 2150 (39.1%)
2 278 (1.50%) 87 (1.58%)
3 34 (0.18%) 7 (0.13%)
Days of Treatment (Fourth or those that follow) . [.;.] 138 [78.8;227] .
Days of Difference Between Treatments (Fifth treatment or those that folow) . [.;.] 277 [140;485] .
Cumulative Days of Treatment (Fourth or those that follow) . [.;.] 692 [460;936] .
Cumulative Difference Between Treatments (Fifth or those that follow) . [.;.] 1412 [1031;1995] .
Average Cumulative Days of Treatment (Fourth or those that follow) . [.;.] 163 [110;221] .
Average Cumulative Difference Between Treatments (Fifth or those that follow) . [.;.] 340 [236;488] .
Comorbidity ICD-10 (with amount of different diagnosis): 0.254
Without psychiatric comorbidity 7191 (38.9%) 2068 (37.6%)
Diagnosis unknown (under study) 4006 (21.7%) 1192 (21.7%)
One 6966 (37.7%) 2150 (39.1%)
Two or more 312 (1.69%) 94 (1.71%)
No. of treatments with 18+ at admission between 2010 and 2019: 0.000
01 18475 (100%) 0 (0.00%)
02 0 (0.00%) 3907 (71.0%)
03 0 (0.00%) 1085 (19.7%)
04 or more 0 (0.00%) 512 (9.30%)
Sexual abuse: <0.001
No sexual abuse 14413 (78.0%) 4467 (81.2%)
Sexual abuse 203 (1.10%) 86 (1.56%)
‘Missing’ 3859 (20.9%) 951 (17.3%)
Domestic violence: <0.001
No domestic violence 10974 (59.4%) 3330 (60.5%)
Domestic violence 3642 (19.7%) 1223 (22.2%)
‘Missing’ 3859 (20.9%) 951 (17.3%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)

Time for this code chunk to run: 0.4 minutes

Show code
library(ggplot2)

jpg_path<-rstudioapi::getSourceEditorContext()$path
if (grepl("CISS Fondecyt",jpg_path)==T){
    jpg_path<-paste0("C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/")
  } else if (grepl("andre",jpg_path)==T){
    jpg_path<-paste0('C:/Users/andre/Desktop/SUD_CL/')
  } else if (grepl("E:",jpg_path)==T){
    jpg_path<-paste0("E:/Mi unidad/Alvacast/SISTRAT 2019 (github)/")
  } else {
    jpg_path<-paste0("G:/Mi unidad/Alvacast/SISTRAT 2019 (github)/")
  }


prueba2 %>% 
 # dplyr::group_by(hash_key)%>%
 # dplyr::mutate(n_hash=n())%>% 
  #dplyr::filter(n_hash>1)%>%
 # slice(1) %>% 
 # ungroup() %>% 
  dplyr::select(dias_treat_imp_sin_na_1,dias_treat_imp_sin_na_2,dias_treat_imp_sin_na_3,dias_treat_imp_sin_na_four) %>%  #mean_cum_dias_trat_sin_na_1
  tidyr::gather(option,value) %>%
  dplyr::mutate(option=dplyr::case_when(option=="dias_treat_imp_sin_na_1"~"01",
                                        option=="dias_treat_imp_sin_na_2"~"02",
                                        option=="dias_treat_imp_sin_na_3"~"03",
                                        option=="dias_treat_imp_sin_na_four"~"04 or more")) %>% 
  dplyr::mutate(option=factor(option)) %>% 
  dplyr::group_by(option) %>% 
  dplyr::mutate(count = length(na.omit(value))) %>% 
  dplyr::ungroup() %>% 
  ggplot(aes(x = option, y=value,group= option)) +
      stat_summary(fun = mean, geom="bar",alpha=.8, na.rm = T)+
    stat_summary(fun = median, geom="point", na.rm = T)+
  stat_summary(fun = median,
                   fun.min = function(x) quantile(x,.25, na.rm = T), 
               fun.max = function(x) quantile(x,.75, na.rm = T), 
               geom = "errorbar", width = 0.5)+
  geom_label(inherit.aes = FALSE, data = . %>% group_by(option) %>% slice(1), 
          aes(label = paste0(count, " Obs."), x = option), y = -0.5)+
  geom_label(inherit.aes = FALSE, data = . %>% group_by(option) %>% slice(1), 
          aes(label = paste0(count, " Obs."), x = option), y = -0.5)+
  theme_bw()+
  theme(plot.caption = element_text(hjust = 0, face= "italic",size=9))+
  #geom_bar(stat = "identity")+
    #geom_errorbar() +
  labs(x="Number of Treatment of Each User", y="Days in Treatment",caption=paste0("Note. Bars=Means, Dots= Medians, Error bars= Percentiles 25 and 75"))
Figura 1. Días de Tratamiento, según la posición del tratamiento en cada usuario usuario

Figure 1: Figura 1. Días de Tratamiento, según la posición del tratamiento en cada usuario usuario

Time for this code chunk to run: 0 minutes

Show code
library(ggplot2)
prueba2 %>% 
 # dplyr::group_by(hash_key)%>%
 # dplyr::mutate(n_hash=n())%>% 
  #dplyr::filter(n_hash>1)%>%
 # slice(1) %>% 
 # ungroup() %>% 
  dplyr::select(diff_bet_treat_1,diff_bet_treat_2,diff_bet_treat_3,diff_bet_treat_four) %>%  #mean_cum_dias_trat_sin_na_1
  tidyr::gather(option,value) %>%
  dplyr::mutate(option=dplyr::case_when(option=="diff_bet_treat_1"~"01",
                                        option=="diff_bet_treat_2"~"02",
                                        option=="diff_bet_treat_3"~"03",
                                        option=="diff_bet_treat_four"~"04 or more")) %>%
  dplyr::mutate(option=factor(option)) %>% 
  dplyr::group_by(option) %>% 
  dplyr::mutate(count = length(na.omit(value))) %>% 
  dplyr::ungroup() %>% 
  ggplot(aes(x = option, y=value,group= option)) +
      stat_summary(fun = mean, geom="bar",alpha=.8, na.rm = T)+
    stat_summary(fun = median, geom="point", na.rm = T)+
  stat_summary(fun = median,
                   fun.min = function(x) quantile(x,.25, na.rm = T), 
                   fun.max = function(x) quantile(x,.75, na.rm = T), 
                   geom = "errorbar", width = 0.5)+
  #geom_label(inherit.aes = F,aes(x = option, y=value, label = max(count, na.rm=T)), vjust = -0.5)+  
  geom_label(inherit.aes = FALSE, data = . %>% group_by(option) %>% slice(1), 
            aes(label = paste0(count, " Obs."), x = option), y = -0.5)+
  theme_bw()+
  theme(plot.caption = element_text(hjust = 0, face= "italic",size=9))+
  #geom_bar(stat = "identity")+
    #geom_errorbar() +
  labs(x="Number of Treatment of Each User", y="Difference (in days) with the posterior treatment",caption=paste0("Note. Bars=Means, Dots= Medians, Error bars= Percentiles 25 and 75"))
Figura 2. Diferencia en Días con el Tratamiento Siguiente, según la posición del tratamiento en cada usuario usuario

Figure 2: Figura 2. Diferencia en Días con el Tratamiento Siguiente, según la posición del tratamiento en cada usuario usuario

Time for this code chunk to run: 0 minutes

Show code
library(ggplot2)
f3<-
prueba2 %>% 
 # dplyr::group_by(hash_key)%>%
 # dplyr::mutate(n_hash=n())%>% 
  #dplyr::filter(n_hash>1)%>%
 # slice(1) %>% 
 # ungroup() %>% 
  dplyr::select(con_quien_vive_joel,dias_treat_imp_sin_na_1,dias_treat_imp_sin_na_2,dias_treat_imp_sin_na_3,dias_treat_imp_sin_na_four) %>%  #mean_cum_dias_trat_sin_na_1con_quien_vive_joel
  tidyr::gather(option,value,-con_quien_vive_joel) %>%
  dplyr::mutate(option=dplyr::case_when(option=="dias_treat_imp_sin_na_1"~"01",
                                        option=="dias_treat_imp_sin_na_2"~"02",
                                        option=="dias_treat_imp_sin_na_3"~"03",
                                        option=="dias_treat_imp_sin_na_four"~"04 or more")) %>% 
  dplyr::mutate(option=factor(option)) %>% 
  dplyr::group_by(con_quien_vive_joel,option) %>% 
  dplyr::mutate(count = length(na.omit(value))) %>% 
  dplyr::ungroup() %>% 
  ggplot(aes(x = option, y=value,group= option)) +
      stat_summary(fun = mean, geom="bar",alpha=.8, na.rm = T)+
    stat_summary(fun = median, geom="point", na.rm = T)+
  stat_summary(fun = median,
                   fun.min = function(x) quantile(x,.25, na.rm = T), 
               fun.max = function(x) quantile(x,.75, na.rm = T), 
               geom = "errorbar", width = 0.5)+
  geom_label(inherit.aes = FALSE, data = . %>% group_by(option,con_quien_vive_joel) %>% slice(1), 
          aes(label = paste0("n=",count), x = option), y = -0.5)+
  geom_label(inherit.aes = FALSE, data = . %>% group_by(option,con_quien_vive_joel) %>% slice(1), 
          aes(label = paste0("n=",count), x = option), y = -0.5)+
  facet_wrap(~con_quien_vive_joel)+
  theme_bw()+
  theme(plot.caption = element_text(hjust = 0, face= "italic",size=9))+
  #geom_bar(stat = "identity")+
    #geom_errorbar() +
  labs(x="Number of Treatment of Each User", y="Days in Treatment",caption=paste0("Note. Bars=Means, Dots= Medians, Error bars= Percentiles 25 and 75"))

f3
Figura 3. Días de Tratamiento, según la posición del tratamiento en cada usuario usuario

Figure 3: Figura 3. Días de Tratamiento, según la posición del tratamiento en cada usuario usuario

Show code
no_mostrar=0


if(no_mostrar==1){
jpeg(paste0(jpg_path,"fig3_joel.jpg"), height=10, width= 10, res= 320, units = "in")
f3
dev.off()
}

Time for this code chunk to run: 0 minutes


Imputation (October 2021)


We generated a plot to see all the missing values in the sample.


Show code
#<div style="border: 1px solid #ddd; padding: 5px; overflow-y: scroll; height:400px; overflow-x: scroll; width:100%">
library(dplyr)
library(ggplot2)

# 
# sexo_2=3,
# escolaridad_rec=3,   76 (0.32%)
# estado_conyugal_2=3, 27 (0.11%)
# edad_ini_sus_prin=2, 2755 (11,5%)
# edad_al_ing=2,
# sus_ini_mod=3, 2074 (8.65%)
# sus_ini_mod_mvv=3, 2074 (8.65%)
# freq_cons_sus_prin=3, 122 (0.51%)
# via_adm_sus_prin_act=3, 4 (0.02%)
# con_quien_vive_joel=3, 
# numero_de_hijos_mod_joel=2, 293 (1,2%)
# condicion_ocupacional_corr=3, 14358 (59.9%)
# cat_ocupacional_corr=3, 14358 (59.9%)
# abandono_temprano=3,
# dg_cie_10_rec=3,
# dias_treat_imp_sin_na=2,
# cnt_mod_cie_10_or=3,
# cnt_diagnostico_trs_fisico=2,
# cnt_otros_probl_at_sm_or=2,
# tipo_de_plan_2_mod=3, 26 (0.11%)
# cnt_mod_cie_10_dg_cons_sus_or= 3,
# dg_total_cie_10 = 3,
# comorbidity_icd_10 = 3,
# compromiso_biopsicosocial 438 (1.83%)
# tenencia_de_la_vivienda_mod 1206 (5.03%)


vector_variables<-
c("sexo_2", "escolaridad_rec", "estado_conyugal_2", "edad_ini_cons", "sus_ini_mod_mvv", "freq_cons_sus_prin", "condicion_ocupacional_corr", "via_adm_sus_prin_act", "con_quien_vive_joel", "numero_de_hijos_mod_joel", "condicion_ocupacional_corr", "dias_treat_imp_sin_na", "cnt_mod_cie_10_or", "tipo_de_plan_2_mod", "comorbidity_icd_10", "compromiso_biopsicosocial", "tenencia_de_la_vivienda_mod","tipo_centro","macrozona","compromiso_biopsicosocial")

missing.values<-
prueba2 %>%
  rowwise %>%
  dplyr::mutate_at(.vars = vars(vector_variables),
                   .funs = ~ifelse(is.na(.), 1, 0)) %>% 
  dplyr::ungroup() %>% 
  dplyr::summarise_at(vars(vector_variables),~sum(.))
#t(missing.values)

miss_val_bar<-
data.table::melt(missing.values) %>% 
    mutate(perc=scales::percent(value/nrow(prueba2))) %>% 
    arrange(desc(perc))

plot_miss<-
missing.values %>%
  data.table::melt() %>%  #condicion_ocupacional_corr
  dplyr::filter(!variable %in% c("row", "hash_key", "dias_treat_imp_sin_na", "dup")) %>% 
  dplyr::mutate(perc= value/sum(nrow(prueba2))) %>% 
  dplyr::mutate(label_text= paste0("Variable= ",variable,"<br>n= ",value,"<br>",scales::percent(round(perc,3)))) %>%
  dplyr::mutate(perc=perc*100) %>% 
  ggplot() +
  geom_bar(aes(x=factor(variable), y=perc,label= label_text), stat = 'identity') +
  sjPlot::theme_sjplot()+
#  scale_y_continuous(limits=c(0,1), labels=percent)+
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size=9))+
  labs(x=NULL, y="% of Missing Values", caption=paste0("Nota. Percentage of missing values (n= ",format(nrow(prueba2),big.mark=","),")"))

  ggplotly(plot_miss, tooltip = c("label_text"))%>% layout(xaxis= list(showticklabels = T), height = 600, width=800) %>%   layout(yaxis = list(tickformat='%',  range = c(0, 15)))

Figure 4: Figure 3. Bar plot of Percentage of Missing Values per Variables at Basline

Show code
  #</div>

Time for this code chunk to run: 0.4 minutes














From the figure above, we could see that the Age of Onset of Drug Use (edad_ini_cons), Starting substance (sus_ini_mod_mvv), the Substance Tenure status of households (tenencia_de_la_vivienda_mod) and the Biopsychosocial Involvement (compromiso_biopsicosocial) had a proportion of missing values, but no greater than 5%. This is why we imputed these values under MAR assumption.


Show code
vector_variables_only_for_imputation<-
c("row","hash_key", "edad_al_ing", "sexo_2", "escolaridad_rec", "estado_conyugal_2", "edad_ini_cons", "sus_ini_mod_mvv", "freq_cons_sus_prin", "condicion_ocupacional_corr", "via_adm_sus_prin_act", "con_quien_vive_joel", "numero_de_hijos_mod_joel", "condicion_ocupacional_corr", "dias_treat_imp_sin_na", "tipo_de_plan_2_mod", "comorbidity_icd_10", "compromiso_biopsicosocial", "tenencia_de_la_vivienda_mod", "tipo_centro", "macrozona", "compromiso_biopsicosocial", "sus_ini_mod")#cnt_mod_cie_10_or", 

#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:

prueba2_miss<-
prueba2 %>% 
    #dplyr::group_by(hash_key) %>% 
    #dplyr::mutate(rn=row_number()) %>% 
    #dplyr::ungroup() %>% 
  
  #:#:#:#:#:#:#:#:#:#:#:
  # ORDINALIZAR LAS VARIABLES ORDINALES: 
  dplyr::select_(.dots = vector_variables_only_for_imputation) %>% 
  dplyr::mutate(numero_de_hijos_mod_joel=dplyr::case_when(numero_de_hijos_mod_joel>3~"4 or more",
                                                          T~as.character(numero_de_hijos_mod_joel))) %>% 
  #dplyr::select(-hash_key) %>% 
  as.data.frame()
  
#CONS_C1_df_dup_SEP_2020 %>% janitor::tabyl(evaluacindelprocesoteraputico) 
#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:

#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:#:
time_before_missforest<-Sys.time()


# for (var in colnames(prueba2_miss)) {
#   attr(prueba2_miss[[deparse(as.name(var))]], "label") <- NULL
# }


library(missRanger)
set.seed(2125)
prueba2_imp <- missRanger(
                prueba2_miss, 
                formula = . ~ . - row - hash_key,
                num.trees = 200, 
                returnOOB=T,
                maxiter=50,
                verbose = 2, 
                seed = 2125)


time_after_missforest<-Sys.time()

paste0("Time in imputation process: ");time_after_missforest-time_before_missforest

Time for this code chunk to run: 0.4 minutes


Show code
ggplotly(DataExplorer::plot_missing(prueba2,missing_only = T))
Figure 4. Plot of missing values in the original sample

Figure 5: Figure 4. Plot of missing values in the original sample

Figure 5: Figure 4. Plot of missing values in the original sample

Time for this code chunk to run: 0 minutes


Descriptives

Show code
attr(prueba2_imp$numero_de_hijos_mod_joel,"label") <-"Number of Children (Max. Value), adding 1 if pregnant at admission"
attr(prueba2$cnt_mod_cie_10_or,"label") <- "Total count of Psychiatric Diagnostics"
attr(prueba2_imp$escolaridad_rec,"label") <- "Educational Attainment"



table6_imp <- compareGroups::compareGroups(no_group ~ sexo_2+ escolaridad_rec+ estado_conyugal_2+ compromiso_biopsicosocial+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ con_quien_vive_joel+ numero_de_hijos_mod_joel+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+ tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+ cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+ max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+ dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(sexo_2=3,
                                                 escolaridad_rec=3,
                                                 estado_conyugal_2=3,
                                                 compromiso_biopsicosocial=2,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 con_quien_vive_joel=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2, 
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered= 3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 2,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence = 3
                                                 ),
                                       data = cbind.data.frame(prueba2_imp,
                                                  dplyr::select(prueba2,cum_dias_trat_sin_na_1, cum_dias_trat_sin_na_2, cum_dias_trat_sin_na_3, cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10, dias_treat_imp_sin_na_1, dias_treat_imp_sin_na_2, dias_treat_imp_sin_na_3, dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10, cum_diff_bet_treat_1, cum_diff_bet_treat_2, cum_diff_bet_treat_3, cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10),
                        #
                                                  dplyr::select(prueba2,sus_principal_mod, cat_ocupacional_corr, cnt_diagnostico_trs_fisico, cnt_otros_probl_at_sm_or, dg_cie_10_rec, abandono_temprano, duplicates_filtered, max_cum_dias_trat_sin_na, max_cum_diff_bet_treat, cnt_mod_cie_10_dg_cons_sus_or, cnt_mod_cie_10_or, dg_total_cie_10, dias_treat_imp_sin_na_four, diff_bet_treat_four, cum_dias_trat_sin_na_four, cum_diff_bet_treat_four, mean_cum_dias_trat_sin_na_four, mean_cum_diff_bet_treat_four, n_treats, sex_abuse, dom_violence))%>% dplyr::mutate(no_group=1),
                                       include.miss = T,
                                       var.equal=T
)

pvals <- getResults(table6_imp)

restab6_imp <- createTable(table6_imp,show.p.overall = F)
compareGroups::export2md(restab6_imp, size=9, first.strip=T, hide.no="no", position="center",col.names=c("Variables","Total"),
                         format="html",caption= "Summary descriptives")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 4: Summary descriptives
Variables Total
N=23979
Sexo Usuario/Sex of User:
Men 19850 (82.8%)
Women 4129 (17.2%)
Educational Attainment:
3-Completed primary school or less 5638 (23.5%)
2-Completed high school or less 14586 (60.8%)
1-More than high school 3755 (15.7%)
Estado Conyugal/Marital Status:
Married/Shared living arrangements 5137 (21.4%)
Separated/Divorced 501 (2.09%)
Single 18311 (76.4%)
Widower 30 (0.13%)
Biopsychosocial Compromise:
1-Mild 2245 (9.36%)
2-Moderate 14309 (59.7%)
3-Severe 7425 (31.0%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 14.9 [13.0;16.0]
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 25.4 [22.6;27.7]
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent):
Alcohol 11212 (46.8%)
Cocaine hydrochloride 936 (3.90%)
Cocaine paste 1058 (4.41%)
Marijuana 10362 (43.2%)
Other 411 (1.71%)
Starting Substance:
Alcohol 11053 (46.1%)
Cocaine hydrochloride 972 (4.05%)
Marijuana 10452 (43.6%)
Other 398 (1.66%)
Cocaine paste 1104 (4.60%)
freq_cons_sus_prin:
1 day a week or more 1616 (6.74%)
2 to 3 days a week 7128 (29.7%)
4 to 6 days a week 4108 (17.1%)
Daily 9961 (41.5%)
Less than 1 day a week 1166 (4.86%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f):
Smoked or Pulmonary Aspiration 13906 (58.0%)
Intranasal (powder aspiration) 5575 (23.2%)
Injected Intravenously or Intramuscularly 16 (0.07%)
Oral (drunk or eaten) 4470 (18.6%)
Other 12 (0.05%)
Whom you live with(cohabitation status) (Recoded) (f):
Alone 1335 (5.57%)
Family of origin 15455 (64.5%)
With couple/children 7189 (30.0%)
Number of Children (Max. Value), adding 1 if pregnant at admission:
0 9730 (40.6%)
1 8664 (36.1%)
2 3929 (16.4%)
3 1218 (5.08%)
4 or more 438 (1.83%)
Occupational Status Corrected(f):
Employed 10423 (43.5%)
Inactive 2019 (8.42%)
Looking for a job for the first time 97 (0.40%)
No activity 1333 (5.56%)
Not seeking for work 216 (0.90%)
Unemployed 9891 (41.2%)
Occupational Category Corrected(f):
Employer 322 (1.34%)
Other 222 (0.93%)
Salaried 7039 (29.4%)
Self-employed 1934 (8.07%)
Unpaid family labour 65 (0.27%)
Volunteer worker 39 (0.16%)
‘Missing’ 14358 (59.9%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months):
Mayor o igual a 90 días 17383 (72.5%)
Menos de 90 días 6596 (27.5%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded):
Without psychiatric comorbidity 9259 (38.6%)
Diagnosis unknown (under study) 5198 (21.7%)
With psychiatric comorbidity 9522 (39.7%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 147 [84.0;254]
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00]
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00]
Type of Plan (Independently of the Program):
PAB 9282 (38.7%)
PAI 11407 (47.6%)
PR 3290 (13.7%)
Tenure status of households:
Illegal Settlement 235 (0.98%)
Others 566 (2.36%)
Owner/Transferred dwellings/Pays Dividends 7759 (32.4%)
Renting 4055 (16.9%)
Stays temporarily with a relative 11364 (47.4%)
Cum. Days of Treatment (1st Treatment) 147 [84.0;254]
Cum. Days of Treatment (2nd Treatment) 318 [207;489]
Cum. Days of Treatment (3rd Treatment) 485 [335;704]
Cum. Days of Treatment (4th Treatment) 638 [433;897]
Cum. Days of Treatment (5th Treatment) 805 [550;1041]
Cum. Days of Treatment (6th Treatment) 944 [716;1152]
Cum. Days of Treatment (7th Treatment) 1076 [888;1279]
Cum. Days of Treatment (8th Treatment) 1192 [1152;1232]
Cum. Days of Treatment (9th Treatment) 1403 [1403;1403]
Cum. Days of Treatment (10th Treatment) 1622 [1622;1622]
Days of Treatment (1st Treatment) 147 [84.0;254]
Days of Treatment (2nd Treatment) 137 [77.0;239]
Days of Treatment (3rd Treatment) 134 [73.0;237]
Days of Treatment (4th Treatment) 126 [70.0;224]
Days of Treatment (5th Treatment) 143 [67.0;260]
Days of Treatment (6th Treatment) 145 [76.8;199]
Days of Treatment (7th Treatment) 120 [23.0;175]
Days of Treatment (8th Treatment) 40.0 [29.5;84.5]
Days of Treatment (9th Treatment) 211 [211;211]
Days of Treatment (10th Treatment) 219 [219;219]
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00]
Cum. Diff Between Treatments (2nd Treatment) 801 [405;1390]
Cum. Diff Between Treatments (3rd Treatment) 1155 [686;1680]
Cum. Diff Between Treatments (4th Treatment) 1341 [886;1972]
Cum. Diff Between Treatments (5th Treatment) 1458 [1047;1970]
Cum. Diff Between Treatments (6th Treatment) 1509 [1160;2294]
Cum. Diff Between Treatments (7th Treatment) 1188 [1184;1422]
Cum. Diff Between Treatments (8th Treatment) 1706 [1706;1706]
Cum. Diff Between Treatments (9th Treatment) 1944 [1944;1944]
Cum. Diff Between Treatments (10th Treatment) .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total):
1 18472 (77.0%)
2 3908 (16.3%)
3 1087 (4.53%)
4 347 (1.45%)
5 111 (0.46%)
6 37 (0.15%)
7 14 (0.06%)
8 2 (0.01%)
10 1 (0.00%)
Max. Cumulative Days of Treatment 182 [98.0;332]
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00]
Total count of Psychiatric & Drug dependence Diagnostics 1.00 [1.00;2.00]
Total count of Psychiatric Diagnostics:
0 9259 (38.6%)
1 14314 (59.7%)
2 365 (1.52%)
3 41 (0.17%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses):
0 14457 (60.3%)
1 9116 (38.0%)
2 365 (1.52%)
3 41 (0.17%)
Days of Treatment (Fourth or those that follow) 138 [78.8;227]
Days of Difference Between Treatments (Fifth treatment or those that folow) 277 [140;485]
Cumulative Days of Treatment (Fourth or those that follow) 692 [460;936]
Cumulative Difference Between Treatments (Fifth or those that follow) 1412 [1031;1995]
Average Cumulative Days of Treatment (Fourth or those that follow) 163 [110;221]
Average Cumulative Difference Between Treatments (Fifth or those that follow) 340 [236;488]
Comorbidity ICD-10 (with amount of different diagnosis):
Without psychiatric comorbidity 9259 (38.6%)
Diagnosis unknown (under study) 5198 (21.7%)
One 9116 (38.0%)
Two or more 406 (1.69%)
No. of treatments with 18+ at admission between 2010 and 2019:
01 18475 (77.0%)
02 3907 (16.3%)
03 1085 (4.52%)
04 or more 512 (2.14%)
Sexual abuse:
No sexual abuse 18880 (78.7%)
Sexual abuse 289 (1.21%)
‘Missing’ 4810 (20.1%)
Domestic violence:
No domestic violence 14304 (59.7%)
Domestic violence 4865 (20.3%)
‘Missing’ 4810 (20.1%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)

Time for this code chunk to run: 0.1 minutes


Living with

Show code
table5_imp <- compareGroups::compareGroups(con_quien_vive_joel ~ sus_principal_mod+ sexo_2+ escolaridad_rec+ compromiso_biopsicosocial+ estado_conyugal_2+ edad_ini_cons+ edad_al_ing+ sus_ini_mod+ sus_ini_mod_mvv+ freq_cons_sus_prin+ via_adm_sus_prin_act+ numero_de_hijos_mod_joel+ numero_de_hijos_mod_joel_bin+ condicion_ocupacional_corr+ cat_ocupacional_corr+ abandono_temprano+ dg_cie_10_rec+ dias_treat_imp_sin_na+ cnt_diagnostico_trs_fisico+ cnt_otros_probl_at_sm_or+  tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod+ cum_dias_trat_sin_na_1+ cum_dias_trat_sin_na_2+ cum_dias_trat_sin_na_3+ cum_dias_trat_sin_na_4+ cum_dias_trat_sin_na_5+ cum_dias_trat_sin_na_6+ cum_dias_trat_sin_na_7+ cum_dias_trat_sin_na_8+ cum_dias_trat_sin_na_9+ cum_dias_trat_sin_na_10+ dias_treat_imp_sin_na_1+ dias_treat_imp_sin_na_2+ dias_treat_imp_sin_na_3+ dias_treat_imp_sin_na_4+ dias_treat_imp_sin_na_5+ dias_treat_imp_sin_na_6+ dias_treat_imp_sin_na_7+ dias_treat_imp_sin_na_8+ dias_treat_imp_sin_na_9+ dias_treat_imp_sin_na_10+ cum_diff_bet_treat_1+cum_diff_bet_treat_2+ cum_diff_bet_treat_3+ cum_diff_bet_treat_4+ cum_diff_bet_treat_5+ cum_diff_bet_treat_6+ cum_diff_bet_treat_7+ cum_diff_bet_treat_8+ cum_diff_bet_treat_9+ cum_diff_bet_treat_10+ duplicates_filtered+max_cum_dias_trat_sin_na+ max_cum_diff_bet_treat+ cnt_mod_cie_10_dg_cons_sus_or+ cnt_mod_cie_10_or+ dg_total_cie_10+dias_treat_imp_sin_na_four+ diff_bet_treat_four+ cum_dias_trat_sin_na_four+ cum_diff_bet_treat_four+ mean_cum_dias_trat_sin_na_four+ mean_cum_diff_bet_treat_four+ comorbidity_icd_10+ n_treats+ sex_abuse+ dom_violence,
                                       method= c(sus_principal_mod=3,
                                                 sexo_2=3,
                                                 escolaridad_rec=3,
                                                 compromiso_biopsicosocial=2,
                                                 estado_conyugal_2=3,
                                                 edad_ini_cons=2,
                                                 edad_al_ing=2,
                                                 sus_ini_mod=3,
                                                 sus_ini_mod_mvv=3,
                                                 freq_cons_sus_prin=3,
                                                 via_adm_sus_prin_act=3,
                                                 numero_de_hijos_mod_joel=2,
                                                 numero_de_hijos_mod_joel_bin=2,
                                                 condicion_ocupacional_corr=3,
                                                 cat_ocupacional_corr=3,
                                                 abandono_temprano=3,
                                                 dg_cie_10_rec=3,
                                                 dias_treat_imp_sin_na=2,
                                                 cnt_mod_cie_10_or=3,
                                                 cnt_diagnostico_trs_fisico=2,
                                                 cnt_otros_probl_at_sm_or=2,
                                                 tipo_de_plan_2_mod=3,
                                                 tenencia_de_la_vivienda_mod=2,
                                                 cum_dias_trat_sin_na_1= 2,
                                                 cum_dias_trat_sin_na_2= 2, 
                                                 cum_dias_trat_sin_na_3= 2, 
                                                 cum_dias_trat_sin_na_4= 2, 
                                                 cum_dias_trat_sin_na_5= 2, 
                                                 cum_dias_trat_sin_na_6= 2, 
                                                 cum_dias_trat_sin_na_7= 2, 
                                                 cum_dias_trat_sin_na_8= 2, 
                                                 cum_dias_trat_sin_na_9= 2, 
                                                 cum_dias_trat_sin_na_10=2, 
                                                 dias_treat_imp_sin_na_1= 2,
                                                 dias_treat_imp_sin_na_2= 2, 
                                                 dias_treat_imp_sin_na_3= 2, 
                                                 dias_treat_imp_sin_na_4= 2, 
                                                 dias_treat_imp_sin_na_5= 2, 
                                                 dias_treat_imp_sin_na_6= 2, 
                                                 dias_treat_imp_sin_na_7= 2, 
                                                 dias_treat_imp_sin_na_8= 2, 
                                                 dias_treat_imp_sin_na_9= 2, 
                                                 dias_treat_imp_sin_na_10=2,                                                  
                                                 cum_diff_bet_treat_1= 2, 
                                                 cum_diff_bet_treat_2= 2, 
                                                 cum_diff_bet_treat_3= 2, 
                                                 cum_diff_bet_treat_4= 2, 
                                                 cum_diff_bet_treat_5= 2, 
                                                 cum_diff_bet_treat_6= 2, 
                                                 cum_diff_bet_treat_7= 2, 
                                                 cum_diff_bet_treat_8= 2, 
                                                 cum_diff_bet_treat_9= 2, 
                                                 cum_diff_bet_treat_10= 2,
                                                 duplicates_filtered=3,
                                                 max_cum_dias_trat_sin_na= 2,
                                                 max_cum_diff_bet_treat= 2,
                                                 cnt_mod_cie_10_dg_cons_sus_or= 3,
                                                 dg_total_cie_10 = 3,
                                                 comorbidity_icd_10 = 3,
                                                 dias_treat_imp_sin_na_four = 2,
                                                 diff_bet_treat_four = 2,
                                                 cum_dias_trat_sin_na_four = 2,
                                                 cum_diff_bet_treat_four = 2,
                                                 mean_cum_dias_trat_sin_na_four = 2,
                                                 mean_cum_diff_bet_treat_four = 2,
                                                 n_treats = 3,
                                                 sex_abuse = 3,
                                                 dom_violence = 3
                                       ),
                                       data = cbind.data.frame(prueba2_imp,
                                                  dplyr::select(prueba2,cum_dias_trat_sin_na_1, cum_dias_trat_sin_na_2, cum_dias_trat_sin_na_3, cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10, dias_treat_imp_sin_na_1, dias_treat_imp_sin_na_2, dias_treat_imp_sin_na_3, dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10, cum_diff_bet_treat_1, cum_diff_bet_treat_2, cum_diff_bet_treat_3, cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10),
                        #
                                                  dplyr::select(prueba2,sus_principal_mod, cat_ocupacional_corr, cnt_diagnostico_trs_fisico, cnt_otros_probl_at_sm_or, dg_cie_10_rec, abandono_temprano, duplicates_filtered, max_cum_dias_trat_sin_na, max_cum_diff_bet_treat, cnt_mod_cie_10_dg_cons_sus_or, cnt_mod_cie_10_or, dg_total_cie_10, dias_treat_imp_sin_na_four, diff_bet_treat_four, cum_dias_trat_sin_na_four, cum_diff_bet_treat_four, mean_cum_dias_trat_sin_na_four, mean_cum_diff_bet_treat_four, n_treats, sex_abuse, dom_violence)) %>% 
                          dplyr::mutate(numero_de_hijos_mod_joel_bin=dplyr::case_when(numero_de_hijos_mod_joel=="0"~"0",
                                                                                 !is.na(numero_de_hijos_mod_joel)~"One or more (or pregnant)")),
                                       include.miss = T,
                                       var.equal=T,
                                       max.xlev = 10,
                                       max.ylev = 10
)#cie_10 cat_ocupacional estatus_ocupacional

#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
if(no_mostrar==1){
  
  catVars_after_imp<-
cbind.data.frame(prueba2_imp,
                 dplyr::select(prueba2,cum_dias_trat_sin_na_1, cum_dias_trat_sin_na_2, cum_dias_trat_sin_na_3, cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10, dias_treat_imp_sin_na_1, dias_treat_imp_sin_na_2, dias_treat_imp_sin_na_3, dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10, cum_diff_bet_treat_1, cum_diff_bet_treat_2, cum_diff_bet_treat_3, cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10),
                 #
                 dplyr::select(prueba2,sus_principal_mod, cat_ocupacional_corr, cnt_diagnostico_trs_fisico, cnt_otros_probl_at_sm_or, dg_cie_10_rec, abandono_temprano, duplicates_filtered, max_cum_dias_trat_sin_na, max_cum_diff_bet_treat, cnt_mod_cie_10_dg_cons_sus_or, cnt_mod_cie_10_or, dg_total_cie_10, dias_treat_imp_sin_na_four, diff_bet_treat_four, cum_dias_trat_sin_na_four, cum_diff_bet_treat_four, mean_cum_dias_trat_sin_na_four, mean_cum_diff_bet_treat_four, n_treats, sex_abuse, dom_violence)) %>% 
    dplyr::mutate(numero_de_hijos_mod_joel_bin=dplyr::case_when(numero_de_hijos_mod_joel=="0"~"0",
                                                                !is.na(numero_de_hijos_mod_joel)~"One or more (or pregnant)")) %>% 
    dplyr::select_if(~!is.numeric(.x)) %>% names()
#prueba
cbind.data.frame(prueba2_imp,
                                                  dplyr::select(prueba2,cum_dias_trat_sin_na_1, cum_dias_trat_sin_na_2, cum_dias_trat_sin_na_3, cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10, dias_treat_imp_sin_na_1, dias_treat_imp_sin_na_2, dias_treat_imp_sin_na_3, dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10, cum_diff_bet_treat_1, cum_diff_bet_treat_2, cum_diff_bet_treat_3, cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10),
                        #
                                                  dplyr::select(prueba2,sus_principal_mod, cat_ocupacional_corr, cnt_diagnostico_trs_fisico, cnt_otros_probl_at_sm_or, dg_cie_10_rec, abandono_temprano, duplicates_filtered, max_cum_dias_trat_sin_na, max_cum_diff_bet_treat, cnt_mod_cie_10_dg_cons_sus_or, cnt_mod_cie_10_or, dg_total_cie_10, dias_treat_imp_sin_na_four, diff_bet_treat_four, cum_dias_trat_sin_na_four, cum_diff_bet_treat_four, mean_cum_dias_trat_sin_na_four, mean_cum_diff_bet_treat_four, n_treats, sex_abuse, dom_violence)) %>% 
                          dplyr::mutate(numero_de_hijos_mod_joel_bin=dplyr::case_when(numero_de_hijos_mod_joel=="0"~"0",
                                                                                 !is.na(numero_de_hijos_mod_joel)~"One or more (or pregnant)")) %>% 
    dplyr::select(catVars_after_imp) %>% 
    tidyr::gather(variable,measure, -con_quien_vive_joel) %>% 
    group_by(variable) %>%
    do(chisq.test(.$con_quien_vive_joel, .$measure) %>% broom::tidy()) %>%
    dplyr::mutate(p.value=ifelse(p.value<.001,"<0.001",sprintf("%1.3f",p.value))) %>% 
    dplyr::mutate(statistic=sprintf("%2.2f",statistic)) %>% 
    dplyr::mutate(report=paste0("X²(",parameter,", N=",nrow(prueba2),")=",statistic,ifelse(p.value=="<0.001",p.value, paste0("=",p.value)))) %>% copiar_nombres()
}

if(no_mostrar==1){
  
  invisible("Prueba post-revisión para sacar el wilcox y test de asociaciones")
broom::tidy(wilcox.test(dias_treat_imp_sin_na ~ tipo_de_programa_2, data=CONS_C1_df_dup_SEP_2020_women_miss_after_imp_conservados)) %>% dplyr::mutate(report=paste0("W"))
  
#effect size
broom::tidy(wilcox.test(dias_treat_imp_sin_na ~ tipo_de_programa_2, data=CONS_C1_df_dup_SEP_2020_women_miss_after_imp_conservados))$statistic/sqrt(nrow(CONS_C1_df_dup_SEP_2020_women_miss_after_imp_conservados))
  
broom::tidy(t.test(dias_treat_imp_sin_na ~ tipo_de_programa_2, data=CONS_C1_df_dup_SEP_2020_women_miss_after_imp_conservados)) %>% 
  dplyr::mutate(report=paste0("t(",round(parameter,0),")=",sprintf("%1.2f",statistic),",",ifelse(p.value<0.001,"<0.001", paste0("=",sprinf("f1.3f",p.value)))))
  # t(19) = 3.1, p = .006.
}
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_#_
pvals <- getResults(table5_imp)
#p.adjust(pvals, method = "BH")
restab5_imp <- createTable(table5_imp, show.p.overall = T)
compareGroups::export2md(restab5_imp, size=9, first.strip=T, hide.no="no", position="center",col.names=c("Variables","Alone","Family of origin", "With couple", "P-value"),
                         format="html",caption= "Summary descriptives by With whom they live (with some imputed variables")%>%
  kableExtra::add_footnote(c("Note. Variables of C1 dataset had to be standardized before comparison;", "Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;", "Categorical variables are presented as number (%)"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 5: Summary descriptives by With whom they live (with some imputed variables
Variables Alone Family of origin With couple P-value
N=1335 N=15455 N=7189
Sustancia Principal de Consumo (Sólo más frecuentes)(f)/Primary or Main Substance of Consumption at Admission (Only more frequent)(f): <0.001
Alcohol 311 (23.3%) 2434 (15.7%) 1397 (19.4%)
Cocaine hydrochloride 199 (14.9%) 3384 (21.9%) 1811 (25.2%)
Marijuana 148 (11.1%) 2031 (13.1%) 693 (9.64%)
Other 16 (1.20%) 222 (1.44%) 57 (0.79%)
Cocaine paste 661 (49.5%) 7384 (47.8%) 3231 (44.9%)
Sexo Usuario/Sex of User: <0.001
Men 1171 (87.7%) 13154 (85.1%) 5525 (76.9%)
Women 164 (12.3%) 2301 (14.9%) 1664 (23.1%)
Educational Attainment: <0.001
3-Completed primary school or less 359 (26.9%) 3336 (21.6%) 1943 (27.0%)
2-Completed high school or less 774 (58.0%) 9456 (61.2%) 4356 (60.6%)
1-More than high school 202 (15.1%) 2663 (17.2%) 890 (12.4%)
Biopsychosocial Compromise: <0.001
1-Mild 92 (6.89%) 1332 (8.62%) 821 (11.4%)
2-Moderate 649 (48.6%) 9080 (58.8%) 4580 (63.7%)
3-Severe 594 (44.5%) 5043 (32.6%) 1788 (24.9%)
Estado Conyugal/Marital Status: .
Married/Shared living arrangements 101 (7.57%) 858 (5.55%) 4178 (58.1%)
Separated/Divorced 55 (4.12%) 361 (2.34%) 85 (1.18%)
Single 1178 (88.2%) 14212 (92.0%) 2921 (40.6%)
Widower 1 (0.07%) 24 (0.16%) 5 (0.07%)
Edad de Inicio de Consumo/Age of Onset of Drug Use 14.0 [13.0;16.0] 15.0 [13.0;16.0] 14.9 [13.0;16.0] <0.001
Edad a la Fecha de Ingreso a Tratamiento (numérico continuo) (Primera Entrada)/Age at Admission to Treatment (First Entry) 26.3 [23.5;28.3] 24.7 [22.0;27.3] 26.4 [24.1;28.3] <0.001
Sustancia de Inicio (Sólo más frecuentes)/Starting Substance (Only more frequent): <0.001
Alcohol 634 (47.5%) 7046 (45.6%) 3532 (49.1%)
Cocaine hydrochloride 37 (2.77%) 548 (3.55%) 351 (4.88%)
Cocaine paste 68 (5.09%) 637 (4.12%) 353 (4.91%)
Marijuana 570 (42.7%) 6974 (45.1%) 2818 (39.2%)
Other 26 (1.95%) 250 (1.62%) 135 (1.88%)
Starting Substance: <0.001
Alcohol 628 (47.0%) 6926 (44.8%) 3499 (48.7%)
Cocaine hydrochloride 39 (2.92%) 571 (3.69%) 362 (5.04%)
Marijuana 573 (42.9%) 7045 (45.6%) 2834 (39.4%)
Other 24 (1.80%) 245 (1.59%) 129 (1.79%)
Cocaine paste 71 (5.32%) 668 (4.32%) 365 (5.08%)
freq_cons_sus_prin: <0.001
1 day a week or more 55 (4.12%) 904 (5.85%) 657 (9.14%)
2 to 3 days a week 331 (24.8%) 4375 (28.3%) 2422 (33.7%)
4 to 6 days a week 204 (15.3%) 2739 (17.7%) 1165 (16.2%)
Daily 700 (52.4%) 6804 (44.0%) 2457 (34.2%)
Less than 1 day a week 45 (3.37%) 633 (4.10%) 488 (6.79%)
Vía de Administración de la Sustancia Principal (Se aplicaron criterios de limpieza)(f)/Route of Administration of the Primary or Main Substance (Tidy)(f): .
Smoked or Pulmonary Aspiration 799 (59.9%) 9269 (60.0%) 3838 (53.4%)
Intranasal (powder aspiration) 205 (15.4%) 3505 (22.7%) 1865 (25.9%)
Injected Intravenously or Intramuscularly 2 (0.15%) 12 (0.08%) 2 (0.03%)
Oral (drunk or eaten) 328 (24.6%) 2662 (17.2%) 1480 (20.6%)
Other 1 (0.07%) 7 (0.05%) 4 (0.06%)
Number of Children (Max. Value), adding 1 if pregnant at admission: 0.000
0 586 (43.9%) 8149 (52.7%) 995 (13.8%)
1 463 (34.7%) 4959 (32.1%) 3242 (45.1%)
2 184 (13.8%) 1724 (11.2%) 2021 (28.1%)
3 70 (5.24%) 477 (3.09%) 671 (9.33%)
4 or more 32 (2.40%) 146 (0.94%) 260 (3.62%)
numero_de_hijos_mod_joel_bin: 0.000
0 586 (43.9%) 8149 (52.7%) 995 (13.8%)
One or more (or pregnant) 749 (56.1%) 7306 (47.3%) 6194 (86.2%)
Occupational Status Corrected(f): <0.001
Employed 648 (48.5%) 5601 (36.2%) 4174 (58.1%)
Inactive 57 (4.27%) 1231 (7.97%) 731 (10.2%)
Looking for a job for the first time 3 (0.22%) 78 (0.50%) 16 (0.22%)
No activity 86 (6.44%) 1015 (6.57%) 232 (3.23%)
Not seeking for work 34 (2.55%) 154 (1.00%) 28 (0.39%)
Unemployed 507 (38.0%) 7376 (47.7%) 2008 (27.9%)
Occupational Category Corrected(f): .
Employer 14 (1.05%) 163 (1.05%) 145 (2.02%)
Other 17 (1.27%) 128 (0.83%) 77 (1.07%)
Salaried 432 (32.4%) 3833 (24.8%) 2774 (38.6%)
Self-employed 119 (8.91%) 953 (6.17%) 862 (12.0%)
Unpaid family labour 1 (0.07%) 52 (0.34%) 12 (0.17%)
Volunteer worker 2 (0.15%) 25 (0.16%) 12 (0.17%)
‘Missing’ 750 (56.2%) 10301 (66.7%) 3307 (46.0%)
Abandono temprano(<3 meses)/ Early Drop-out(<3 months): <0.001
Mayor o igual a 90 días 865 (64.8%) 11229 (72.7%) 5289 (73.6%)
Menos de 90 días 470 (35.2%) 4226 (27.3%) 1900 (26.4%)
Diagnóstico CIE-10 (1 o más)(Recodificado)/Psychiatric Diagnoses (ICD-10)(one or more)(Recoded): <0.001
Without psychiatric comorbidity 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
Diagnosis unknown (under study) 346 (25.9%) 3322 (21.5%) 1530 (21.3%)
With psychiatric comorbidity 536 (40.1%) 6415 (41.5%) 2571 (35.8%)
Días de Tratamiento (valores perdidos en la fecha de egreso se reemplazaron por la diferencia con 2019-11-13)/Days of Treatment (missing dates of discharge were replaced with difference from 2019-11-13) 125 [68.0;223] 148 [84.0;257] 147 [86.0;253] <0.001
Recuento de Diagnóstico de Trastorno Físico/Count of Physical Disorder 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.015
Recuento de Otros Problemas de Atención Vinculados a Salud Mental/Count of Other problems linked to Mental Health 0.00 [0.00;1.00] 0.00 [0.00;1.00] 0.00 [0.00;1.00] <0.001
Type of Plan (Independently of the Program): <0.001
PAB 391 (29.3%) 5510 (35.7%) 3381 (47.0%)
PAI 587 (44.0%) 7520 (48.7%) 3300 (45.9%)
PR 357 (26.7%) 2425 (15.7%) 508 (7.07%)
Tenure status of households: 0.000
Illegal Settlement 97 (7.27%) 48 (0.31%) 90 (1.25%)
Others 78 (5.84%) 374 (2.42%) 114 (1.59%)
Owner/Transferred dwellings/Pays Dividends 307 (23.0%) 5496 (35.6%) 1956 (27.2%)
Renting 680 (50.9%) 1155 (7.47%) 2220 (30.9%)
Stays temporarily with a relative 173 (13.0%) 8382 (54.2%) 2809 (39.1%)
Cum. Days of Treatment (1st Treatment) 125 [68.0;224] 148 [84.0;257] 147 [86.0;253] <0.001
Cum. Days of Treatment (2nd Treatment) 285 [174;423] 320 [206;493] 326 [218;489] <0.001
Cum. Days of Treatment (3rd Treatment) 463 [260;644] 474 [326;700] 522 [361;730] 0.008
Cum. Days of Treatment (4th Treatment) 526 [339;755] 633 [426;878] 671 [486;941] 0.059
Cum. Days of Treatment (5th Treatment) 690 [532;1120] 798 [541;1047] 876 [576;1021] 0.604
Cum. Days of Treatment (6th Treatment) 460 [356;565] 897 [712;1153] 1006 [868;1144] 0.106
Cum. Days of Treatment (7th Treatment) 477 [376;578] 1165 [993;1331] 1076 [1074;1254] 0.100
Cum. Days of Treatment (8th Treatment) . [.;.] 1152 [1131;1172] 1273 [1273;1273] 0.221
Cum. Days of Treatment (9th Treatment) . [.;.] 1403 [1403;1403] . [.;.] .
Cum. Days of Treatment (10th Treatment) . [.;.] 1622 [1622;1622] . [.;.] .
Days of Treatment (1st Treatment) 125 [68.0;223] 148 [84.0;257] 147 [86.0;253] <0.001
Days of Treatment (2nd Treatment) 119 [57.0;204] 137 [76.0;239] 139 [83.0;245] <0.001
Days of Treatment (3rd Treatment) 127 [71.0;220] 127 [70.0;229] 148 [84.8;246] 0.020
Days of Treatment (4th Treatment) 143 [57.2;248] 125 [70.0;215] 131 [71.0;231] 0.997
Days of Treatment (5th Treatment) 199 [139;335] 138 [67.8;254] 145 [59.2;260] 0.567
Days of Treatment (6th Treatment) 28.0 [17.5;38.5] 149 [121;195] 116 [68.5;205] 0.121
Days of Treatment (7th Treatment) 16.5 [13.2;19.8] 169 [58.5;244] 53.0 [52.0;120] 0.075
Days of Treatment (8th Treatment) . [.;.] 84.5 [62.2;107] 19.0 [19.0;19.0] 0.221
Days of Treatment (9th Treatment) . [.;.] 211 [211;211] . [.;.] .
Days of Treatment (10th Treatment) . [.;.] 219 [219;219] . [.;.] .
Cum. Diff Between Treatments (1st Treatment) 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.812
Cum. Diff Between Treatments (2nd Treatment) 715 [380;1315] 779 [396;1355] 872 [441;1492] 0.075
Cum. Diff Between Treatments (3rd Treatment) 920 [405;1812] 1128 [674;1648] 1235 [770;1697] 0.436
Cum. Diff Between Treatments (4th Treatment) 1290 [1044;2121] 1196 [843;1722] 1448 [1149;2190] 0.034
Cum. Diff Between Treatments (5th Treatment) 2020 [1858;2182] 1470 [1091;1768] 1418 [944;2384] 0.513
Cum. Diff Between Treatments (6th Treatment) 2536 [2415;2657] 1576 [1244;2085] 1221 [1015;1287] 0.174
Cum. Diff Between Treatments (7th Treatment) . [.;.] 1418 [1300;1537] 1188 [1188;1188] 1.000
Cum. Diff Between Treatments (8th Treatment) . [.;.] 1706 [1706;1706] . [.;.] .
Cum. Diff Between Treatments (9th Treatment) . [.;.] 1944 [1944;1944] . [.;.] .
Cum. Diff Between Treatments (10th Treatment) . . . .
Número de Tratamientos por HASH (Total)/Number of Treatments by User (Total): .
1 1033 (77.4%) 11903 (77.0%) 5536 (77.0%)
2 207 (15.5%) 2540 (16.4%) 1161 (16.1%)
3 71 (5.32%) 673 (4.35%) 343 (4.77%)
4 15 (1.12%) 233 (1.51%) 99 (1.38%)
5 7 (0.52%) 69 (0.45%) 35 (0.49%)
6 0 (0.00%) 27 (0.17%) 10 (0.14%)
7 2 (0.15%) 8 (0.05%) 4 (0.06%)
8 0 (0.00%) 1 (0.01%) 1 (0.01%)
10 0 (0.00%) 1 (0.01%) 0 (0.00%)
Max. Cumulative Days of Treatment 154 [80.0;304] 183 [98.0;332] 186 [100;338] <0.001
Max. Cumulative Difference Between Treatments 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.00 [0.00;0.00] 0.883
Total count of Psychiatric & Drug dependence Diagnostics: .
0 224 (16.8%) 2493 (16.1%) 1547 (21.5%)
1 695 (52.1%) 8175 (52.9%) 3827 (53.2%)
2 399 (29.9%) 4536 (29.3%) 1742 (24.2%)
3 16 (1.20%) 226 (1.46%) 67 (0.93%)
4 1 (0.07%) 25 (0.16%) 6 (0.08%)
Total count of Psychiatric Diagnostics: .
0 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
1 860 (64.4%) 9441 (61.1%) 4013 (55.8%)
2 19 (1.42%) 264 (1.71%) 82 (1.14%)
3 3 (0.22%) 32 (0.21%) 6 (0.08%)
Conteo de Diagnósticos CIE-10(sólo diagnósticos)/Count of ICD-10 Diagnostics(only diagnoses): .
0 799 (59.9%) 9040 (58.5%) 4618 (64.2%)
1 514 (38.5%) 6119 (39.6%) 2483 (34.5%)
2 19 (1.42%) 264 (1.71%) 82 (1.14%)
3 3 (0.22%) 32 (0.21%) 6 (0.08%)
Days of Treatment (Fourth or those that follow) 149 [51.8;234] 138 [77.8;225] 137 [85.4;236] 0.966
Days of Difference Between Treatments (Fifth treatment or those that folow) 464 [238;588] 258 [112;416] 288 [164;682] 0.064
Cumulative Days of Treatment (Fourth or those that follow) 590 [364;936] 683 [454;932] 727 [518;999] 0.083
Cumulative Difference Between Treatments (Fifth or those that follow) 1760 [1044;2121] 1345 [943;1759] 1518 [1174;2252] 0.081
Average Cumulative Days of Treatment (Fourth or those that follow) 133 [91.0;209] 162 [107;218] 171 [116;229] 0.080
Average Cumulative Difference Between Treatments (Fifth or those that follow) 348 [261;497] 312 [222;424] 373 [286;544] 0.064
Comorbidity ICD-10 (with amount of different diagnosis): <0.001
Without psychiatric comorbidity 453 (33.9%) 5718 (37.0%) 3088 (43.0%)
Diagnosis unknown (under study) 346 (25.9%) 3322 (21.5%) 1530 (21.3%)
One 514 (38.5%) 6119 (39.6%) 2483 (34.5%)
Two or more 22 (1.65%) 296 (1.92%) 88 (1.22%)
No. of treatments with 18+ at admission between 2010 and 2019: 0.426
01 1034 (77.5%) 11905 (77.0%) 5536 (77.0%)
02 206 (15.4%) 2540 (16.4%) 1161 (16.1%)
03 71 (5.32%) 671 (4.34%) 343 (4.77%)
04 or more 24 (1.80%) 339 (2.19%) 149 (2.07%)
Sexual abuse: 0.034
No sexual abuse 1053 (78.9%) 12207 (79.0%) 5620 (78.2%)
Sexual abuse 27 (2.02%) 175 (1.13%) 87 (1.21%)
‘Missing’ 255 (19.1%) 3073 (19.9%) 1482 (20.6%)
Domestic violence: <0.001
No domestic violence 745 (55.8%) 9509 (61.5%) 4050 (56.3%)
Domestic violence 335 (25.1%) 2873 (18.6%) 1657 (23.0%)
‘Missing’ 255 (19.1%) 3073 (19.9%) 1482 (20.6%)
Note. Variables of C1 dataset had to be standardized before comparison;
Continuous variables are presented as Medians and Percentiles 25 and 75 were shown;
Categorical variables are presented as number (%)
Show code
#janitor::tabyl(prueba2_imp$numero_de_hijos_mod_joel)

Time for this code chunk to run: 0.1 minutes

Outcomes

Univariate or Bivariate Analyses


Here, we compared the incidence rate of those who experienced 1, 2, 3, 1 & 2, 1 to 3, 4 or more, and dropouts in the first treatment, between different “living with” patterns.


Show code
invisible("https://cran.r-project.org/web/packages/riskCommunicator/vignettes/Vignette_newbieRusers.html#continuous-exposure-example")

prueba2_imp2<-
cbind.data.frame(prueba2_imp,
      dplyr::select(prueba2,cum_dias_trat_sin_na_1, cum_dias_trat_sin_na_2, cum_dias_trat_sin_na_3, cum_dias_trat_sin_na_4, cum_dias_trat_sin_na_5, cum_dias_trat_sin_na_6, cum_dias_trat_sin_na_7, cum_dias_trat_sin_na_8, cum_dias_trat_sin_na_9, cum_dias_trat_sin_na_10, dias_treat_imp_sin_na_1, dias_treat_imp_sin_na_2, dias_treat_imp_sin_na_3, dias_treat_imp_sin_na_4, dias_treat_imp_sin_na_5, dias_treat_imp_sin_na_6, dias_treat_imp_sin_na_7, dias_treat_imp_sin_na_8, dias_treat_imp_sin_na_9, dias_treat_imp_sin_na_10, cum_diff_bet_treat_1, cum_diff_bet_treat_2, cum_diff_bet_treat_3, cum_diff_bet_treat_4, cum_diff_bet_treat_5, cum_diff_bet_treat_6, cum_diff_bet_treat_7, cum_diff_bet_treat_8, cum_diff_bet_treat_9, cum_diff_bet_treat_10),
      dplyr::select(prueba2, fech_ing, fech_egres_imp, sus_principal_mod, cat_ocupacional_corr, cnt_diagnostico_trs_fisico, cnt_otros_probl_at_sm_or, dg_cie_10_rec, abandono_temprano, duplicates_filtered, max_cum_dias_trat_sin_na, max_cum_diff_bet_treat, cnt_mod_cie_10_dg_cons_sus_or, cnt_mod_cie_10_or, dg_total_cie_10, dias_treat_imp_sin_na_four, diff_bet_treat_four, cum_dias_trat_sin_na_four, cum_diff_bet_treat_four, mean_cum_dias_trat_sin_na_four, mean_cum_diff_bet_treat_four, n_treats, sex_abuse, dom_violence, motivodeegreso_mod_imp)) %>% 
  dplyr::mutate(person_years=(as.numeric(as.Date("2019-11-13"))- as.numeric(fech_ing))/365.25,
                #2023-02-02
                event= dplyr::case_when(grepl("Drop-out|Administrative", motivodeegreso_mod_imp)~1, T~0),
                yrs_to_tr_dropout= dplyr::case_when(event==1~ dias_treat_imp_sin_na_1/365.25, T~ (as.numeric(as.Date("2019-11-13"))- as.numeric(fech_ing))/365.25),
                max_cum_dias_trat_sin_na_adj= max_cum_dias_trat_sin_na/person_years,
                duplicates_filtered_adj= duplicates_filtered/person_years)#
#n_treats= readmissiones

tablas_inc<-
rbind(data.frame(biostat3::survRate(Surv(person_years, n_treats=="01") ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, n_treats=="02") ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, n_treats=="03") ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, grepl("01|02",n_treats)) ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, grepl("01|02|03",n_treats)) ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, n_treats=="04 or more") ~ con_quien_vive_joel, data=prueba2_imp2)),
      data.frame(biostat3::survRate(Surv(person_years, grepl("Drop", motivodeegreso_mod_imp)) ~ con_quien_vive_joel, data=prueba2_imp2)))

data.table::data.table(tablas_inc, keep.rownames = F)%>% 
  dplyr::mutate(rate=round(rate*1000,0),lower=round(lower*1000,0), upper=round(upper*1000,0))%>% 
knitr::kable(format="html",caption= "Summary of incidence rates of events depending on whom patients live with")%>%
  kableExtra::add_footnote(c("Note. Events per 1,000 person-years"), notation = "none")%>%
  kableExtra::kable_classic() %>% 
  kableExtra::group_rows("Only one treatment",1,3)%>% 
  kableExtra::group_rows("Two treatments",4,6)%>%
  kableExtra::group_rows("Three treatment",7,9)%>% 
  kableExtra::group_rows("One & two treatments",10,12)%>%
  kableExtra::group_rows("One, two & three treatments",13,15)%>%
  kableExtra::group_rows("Four or more treatments",16,18)%>% 
  kableExtra::group_rows("Drop-out from the first treatment",19,21)%>% 
  kableExtra::scroll_box(width = "100%", height = "600px")
Table 6: Summary of incidence rates of events depending on whom patients live with
con_quien_vive_joel tstop event rate lower upper
Only one treatment
Alone 6878.207 1034 150 141 160
Family of origin 78666.565 11905 151 149 154
With couple/children 37054.174 5536 149 145 153
Two treatments
Alone 6878.207 206 30 26 34
Family of origin 78666.565 2540 32 31 34
With couple/children 37054.174 1161 31 30 33
Three treatment
Alone 6878.207 71 10 8 13
Family of origin 78666.565 671 9 8 9
With couple/children 37054.174 343 9 8 10
One & two treatments
Alone 6878.207 1240 180 170 191
Family of origin 78666.565 14445 184 181 187
With couple/children 37054.174 6697 181 176 185
One, two & three treatments
Alone 6878.207 1311 191 180 201
Family of origin 78666.565 15116 192 189 195
With couple/children 37054.174 7040 190 186 194
Four or more treatments
Alone 6878.207 24 3 2 5
Family of origin 78666.565 339 4 4 5
With couple/children 37054.174 149 4 3 5
Drop-out from the first treatment
Alone 6878.207 766 111 104 120
Family of origin 78666.565 8691 110 108 113
With couple/children 37054.174 4417 119 116 123
Note. Events per 1,000 person-years

Time for this code chunk to run: 0 minutes


The amount of treatments (duplicates_filtered) and the maximum cumulative days spent in treatment (max_cum_dias_trat_sin_na) by each user were adjusted by dividing them by the years they were available in the study (we subtracted the date of the first admission to the date of the end of the follow-up).


Show code
rbind(
data.table::data.table(finalfit(prueba2_imp2,'max_cum_dias_trat_sin_na_adj', "con_quien_vive_joel"))[,2:5],
data.table::data.table(finalfit(prueba2_imp2,'duplicates_filtered_adj', "con_quien_vive_joel"))[,2:5], fill= T
) %>% 
  knitr::kable(format="html",caption= "Summary of adjusted measures, depending on whom patients live with") %>% 
  kableExtra::kable_classic() %>% 
  kableExtra::group_rows("Max. Cumulative Days of Treatment",1,3)%>% 
  kableExtra::group_rows("Number of Treatments by User (Total)",4,6)%>%
  kableExtra::add_footnote(c("Note. Outcomes were adjusted for person-years", paste0("First regression= ", ff_metrics(lm(max_cum_dias_trat_sin_na_adj~ con_quien_vive_joel, prueba2_imp2))),paste0("Second regression= ",ff_metrics(lm(duplicates_filtered_adj~ con_quien_vive_joel, prueba2_imp2))  
)), notation = "none")%>%
    kableExtra::scroll_box(width = "100%", height = "350px")
Table 7: Summary of adjusted measures, depending on whom patients live with
unit value Coefficient (univariable)
Max. Cumulative Days of Treatment
Alone Mean (sd) 70.6 (93.5)
Family of origin Mean (sd) 80.1 (91.9) 9.49 (4.44 to 14.55, p<0.001)
With couple/children Mean (sd) 75.9 (86.6) 5.26 (-0.02 to 10.55, p=0.051)
Number of Treatments by User (Total)
Alone Mean (sd) 0.5 (1.1)
Family of origin Mean (sd) 0.6 (1.1) 0.01 (-0.05 to 0.08, p=0.636)
With couple/children Mean (sd) 0.5 (1.0) -0.03 (-0.10 to 0.03, p=0.323)
Note. Outcomes were adjusted for person-years
First regression= Number in dataframe = 23979, Number in model = 23979, Missing = 0, Log-likelihood = -142049.04, AIC = 284106.1, R-squared = 0.00087, Adjusted R-squared = 0.00079
Second regression= Number in dataframe = 23979, Number in model = 23979, Missing = 0, Log-likelihood = -36286.27, AIC = 72580.5, R-squared = 0.00038, Adjusted R-squared = 0.00029

Time for this code chunk to run: 0 minutes


We checked the linear model with adjusted cumulative days of treatment


Show code
cat("Autocorrelation?")  
Autocorrelation?
Show code
lmtest::dwtest(prueba2_imp2$max_cum_dias_trat_sin_na_adj~ prueba2_imp2$con_quien_vive_joel)

    Durbin-Watson test

data:  prueba2_imp2$max_cum_dias_trat_sin_na_adj ~ prueba2_imp2$con_quien_vive_joel
DW = 1.9797, p-value = 0.0583
alternative hypothesis: true autocorrelation is greater than 0
Show code
cat("Pattern in residuals?")  
Pattern in residuals?
Show code
plot(residuals(lm(prueba2_imp2$max_cum_dias_trat_sin_na_adj~ prueba2_imp2$con_quien_vive_joel)))
Show code
cat("Are variances equal?")  
Are variances equal?
Show code
car::leveneTest(prueba2_imp2$max_cum_dias_trat_sin_na_adj,as.factor(prueba2_imp2$con_quien_vive_joel), center = mean)
Levene's Test for Homogeneity of Variance (center = mean)
         Df F value    Pr(>F)    
group     2  16.816 5.037e-08 ***
      23976                      
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Show code
#Como el estadístico de Levene arroja un p-valor inferior a 0,05 
#(Pr>F = 0,023) se rechaza la hipótesis nula de igualdad de varianzas. 

mod<-aov(prueba2_imp2$max_cum_dias_trat_sin_na_adj~as.factor(prueba2_imp2$con_quien_vive_joel))
  contraste <- rbind(c(1,1,-2),c(1,-1,0)) #
#Se entrega al programa los contrastes a utilizar: 
    filas<-c("Alone & Family of origin vs With couple/children","Alone vs Family of origin")
    columnas<-c("Alone","Family of origin","With couple/children")

# contraste se definen un vector de números de acuerdo a las hipótesis formuladas
# función glht que tiene como argumento el modelo ANOVA definido como mod, 
# y definir la variable grupal estado_nutricional= contraste. Por último, realizar un summary.
    
    dimnames(contraste)<-list(filas,columnas)

cat("GLHT: User-defined General linear hypothesis")        
GLHT: User-defined General linear hypothesis
Show code
    compara <-multcomp::glht(mod, linfct = multcomp::mcp(`as.factor(prueba2_imp2$con_quien_vive_joel)`= contraste))
    
    summary(compara)

     Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: User-defined Contrasts


Fit: aov(formula = prueba2_imp2$max_cum_dias_trat_sin_na_adj ~ as.factor(prueba2_imp2$con_quien_vive_joel))

Linear Hypotheses:
                                                      Estimate
Alone & Family of origin vs With couple/children == 0   -1.033
Alone vs Family of origin == 0                          -9.494
                                                      Std. Error
Alone & Family of origin vs With couple/children == 0      3.349
Alone vs Family of origin == 0                             2.581
                                                      t value
Alone & Family of origin vs With couple/children == 0  -0.308
Alone vs Family of origin == 0                         -3.679
                                                      Pr(>|t|)    
Alone & Family of origin vs With couple/children == 0 0.924666    
Alone vs Family of origin == 0                        0.000453 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
(Adjusted p values reported -- single-step method)
Show code
cat("Not assuming equal variances")            
Not assuming equal variances
Show code
    oneway.test(max_cum_dias_trat_sin_na_adj~as.factor(con_quien_vive_joel), 
                          data = prueba2_imp2, 
                          var.equal=FALSE)

    One-way analysis of means (not assuming equal variances)

data:  max_cum_dias_trat_sin_na_adj and as.factor(con_quien_vive_joel)
F = 10.3, num df = 2.0, denom df = 3573.5, p-value = 3.463e-05
Show code
cat("Tukey HSD")
Tukey HSD
Show code
    TukeyHSD(mod)
  Tukey multiple comparisons of means
    95% family-wise confidence level

Fit: aov(formula = prueba2_imp2$max_cum_dias_trat_sin_na_adj ~ as.factor(prueba2_imp2$con_quien_vive_joel))

$`as.factor(prueba2_imp2$con_quien_vive_joel)`
                                           diff       lwr       upr
Family of origin-Alone                 9.494373  3.445382 15.543364
With couple/children-Alone             5.263452 -1.056002 11.582906
With couple/children-Family of origin -4.230921 -7.258117 -1.203725
                                          p adj
Family of origin-Alone                0.0006866
With couple/children-Alone            0.1243273
With couple/children-Family of origin 0.0030289
Show code
cat("Games-Howell")    
Games-Howell
Show code
posthocTGH(prueba2_imp2$con_quien_vive_joel, 
           y = prueba2_imp2$max_cum_dias_trat_sin_na_adj, method= "games-howell", digits=4)
                         n means variances
Alone                 1335 70.63      8749
Family of origin     15455 80.12      8454
With couple/children  7189 75.89      7501

                                        diff  ci.lo  ci.hi     t
Family of origin-Alone                 9.494  3.243 15.746 3.563
With couple/children-Alone             5.263 -1.202 11.729 1.910
With couple/children-Family of origin -4.231 -7.187 -1.275 3.355
                                         df     p
Family of origin-Alone                 1565 .0011
With couple/children-Alone             1784 .1362
With couple/children-Family of origin 14807 .0023
Show code
#https://www.usabart.nl/eval/5-2%20ANOVA.pdf

Time for this code chunk to run: 0 minutes


Survival Analyses (Feb 2023)

Explore

Show code
#make dummy for each treatment arm
prueba2_imp2$con_quien_vive_joel_fam_or<-as.numeric(prueba2_imp2$con_quien_vive_joel=="Family of origin")
prueba2_imp2$con_quien_vive_joel_alone<-as.numeric(prueba2_imp2$con_quien_vive_joel=="Alone")
prueba2_imp2$con_quien_vive_joel_coup_chil<-as.numeric(prueba2_imp2$con_quien_vive_joel=="With couple/children")

biostat3::survRate(Surv(yrs_to_tr_dropout, event) ~ con_quien_vive_joel, data= prueba2_imp2) %>% 
  #dplyr::mutate(rate=round(rate*1000,0),lower=round(lower*1000,0), upper=round(upper*1000,0))%>% 
  knitr::kable("markdown", caption= "Glimpse of the survival analysis, Years to drop-out in the First Treatment by Living Conditions")
Table 8: Glimpse of the survival analysis, Years to drop-out in the First Treatment by Living Conditions
con_quien_vive_joel tstop event rate lower upper
con_quien_vive_joel=Alone Alone 2182.976 926 0.4241916 0.3973065 0.4524172
con_quien_vive_joel=Family of origin Family of origin 27734.735 10209 0.3680944 0.3609883 0.3753052
con_quien_vive_joel=With couple/children With couple/children 11721.960 5076 0.4330334 0.4212017 0.4451131

Time for this code chunk to run: 0 minutes

Show code
dropout_fit<- survfit(Surv(yrs_to_tr_dropout, event) ~ con_quien_vive_joel, data= prueba2_imp2,
                               type      = "kaplan-meier",
                                error     = "greenwood",
                                conf.type = "log-log") 

survminer::ggsurvplot(dropout_fit,
           #fun = "cumhaz",
           conf.int = TRUE,
           legend.labs = c("Alone", "Family of origin", "With couple/children"), 
           risk.table = "abs_pct",
           #ncensor.plot = TRUE,
           ggtheme = theme_classic(base_size=15),
           risk.table.y.text.col = F,
           risk.table.col="black",
           font.tickslab = c(10),
           risk.table.height = .2,
           risk.table.fontsize = 2.5,
           #break.time.by = 365.25,
           pval = T,
           #ylim=c(0,10),
           legend = c(0.75, 0.8), 
           legend.title="Living conditions",
           xlab= "Time (in years)", 
           #cumevents=T,
           surv.connect = T,
           censor= F
           )
Kaplan-Meier curves by Living conditions

Figure 6: Kaplan-Meier curves by Living conditions

Time for this code chunk to run: 0 minutes

We calculated the restricted mean survival time and lost, considering that proportionality of trends could be violated.

Show code
cat("Living with Family of origin vs. Alone and With couple/children at 1 year")
Living with Family of origin vs. Alone and With couple/children at 1 year
Show code
survRM2::rmst2(prueba2_imp2$yrs_to_tr_dropout, prueba2_imp2$event, as.numeric(prueba2_imp2$con_quien_vive_joel=="Family of origin"), tau=1)

The truncation time: tau = 1  was specified. 

Restricted Mean Survival Time (RMST) by arm 
              Est.    se lower .95 upper .95
RMST (arm=1) 0.599 0.003     0.593     0.604
RMST (arm=0) 0.575 0.004     0.568     0.583


Restricted Mean Time Lost (RMTL) by arm 
              Est.    se lower .95 upper .95
RMTL (arm=1) 0.401 0.003     0.396     0.407
RMTL (arm=0) 0.425 0.004     0.417     0.432


Between-group contrast 
                      Est. lower .95 upper .95 p
RMST (arm=1)-(arm=0) 0.024     0.014     0.033 0
RMST (arm=1)/(arm=0) 1.041     1.024     1.058 0
RMTL (arm=1)/(arm=0) 0.945     0.924     0.966 0
Show code
cat("Living with Family of origin vs. Alone and With couple/children at 3 years")
Living with Family of origin vs. Alone and With couple/children at 3 years
Show code
survRM2::rmst2(prueba2_imp2$yrs_to_tr_dropout, prueba2_imp2$event, as.numeric(prueba2_imp2$con_quien_vive_joel=="Family of origin"), tau=3)

The truncation time: tau = 3  was specified. 

Restricted Mean Survival Time (RMST) by arm 
              Est.    se lower .95 upper .95
RMST (arm=1) 1.244 0.010     1.224     1.264
RMST (arm=0) 1.134 0.013     1.108     1.159


Restricted Mean Time Lost (RMTL) by arm 
              Est.    se lower .95 upper .95
RMTL (arm=1) 1.756 0.010     1.736     1.776
RMTL (arm=0) 1.866 0.013     1.841     1.892


Between-group contrast 
                      Est. lower .95 upper .95 p
RMST (arm=1)-(arm=0) 0.110     0.078     0.143 0
RMST (arm=1)/(arm=0) 1.097     1.068     1.128 0
RMTL (arm=1)/(arm=0) 0.941     0.924     0.958 0
Show code
cat("Living with Family of origin vs. Alone and With couple/children at 5 years")
Living with Family of origin vs. Alone and With couple/children at 5 years
Show code
survRM2::rmst2(prueba2_imp2$yrs_to_tr_dropout, prueba2_imp2$event, as.numeric(prueba2_imp2$con_quien_vive_joel=="Family of origin"), tau=5)

The truncation time: tau = 5  was specified. 

Restricted Mean Survival Time (RMST) by arm 
              Est.    se lower .95 upper .95
RMST (arm=1) 1.865 0.018     1.831     1.900
RMST (arm=0) 1.671 0.023     1.627     1.716


Restricted Mean Time Lost (RMTL) by arm 
              Est.    se lower .95 upper .95
RMTL (arm=1) 3.135 0.018     3.100     3.169
RMTL (arm=0) 3.329 0.023     3.284     3.373


Between-group contrast 
                      Est. lower .95 upper .95 p
RMST (arm=1)-(arm=0) 0.194     0.137     0.250 0
RMST (arm=1)/(arm=0) 1.116     1.080     1.153 0
RMTL (arm=1)/(arm=0) 0.942     0.926     0.958 0

Time for this code chunk to run: 0 minutes

Show code
#https://rpubs.com/linpearl89/TTE-RCT
#https://search.r-project.org/CRAN/refmans/adjustedCurves/html/surv_aiptw_pseudo.html
#https://search.r-project.org/CRAN/refmans/adjustedCurves/html/surv_iptw_cox.html
#https://cran.r-project.org/web/packages/RISCA/RISCA.pdf

coxfit <- coxph(Surv(yrs_to_tr_dropout, event) ~ con_quien_vive_joel + edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, ties="efron", data= prueba2_imp2)
   
survminer::ggcoxdiagnostics(coxfit, type = "schoenfeld")

geom_smooth() using formula ‘y ~ x’

Schoefeld residuals

Figure 7: Schoefeld residuals

Show code
ggsave("prueba_scho_plot.png", dpi=640, height=15, width= 15)

geom_smooth() using formula ‘y ~ x’

Time for this code chunk to run: 0.3 minutes

Show code
data.frame(cox.zph(coxfit)$table) %>% 
  knitr::kable("markdown", caption= "Schoefeld residuals")
Table 9: Schoefeld residuals
chisq df p
con_quien_vive_joel 64.692554 2 0.0000000
edad_al_ing 39.352315 1 0.0000000
sexo_2 61.242208 1 0.0000000
escolaridad_rec 4.948839 2 0.0842119
sus_ini_mod_mvv 33.322975 4 0.0000010
freq_cons_sus_prin 190.059855 4 0.0000000
via_adm_sus_prin_act 45.900752 4 0.0000000
condicion_ocupacional_corr 225.182444 5 0.0000000
compromiso_biopsicosocial 137.029722 2 0.0000000
numero_de_hijos_mod_joel 27.132276 4 0.0000187
tipo_de_plan_2_mod 705.936689 2 0.0000000
tenencia_de_la_vivienda_mod 44.136105 4 0.0000000
tipo_centro 574.013144 1 0.0000000
cnt_mod_cie_10_dg_cons_sus_or 105.519418 1 0.0000000
sus_principal_mod 62.813227 4 0.0000000
macrozona 132.264481 2 0.0000000
cnt_mod_cie_10_or 690.849027 3 0.0000000
GLOBAL 2822.282319 46 0.0000000

Time for this code chunk to run: 0 minutes

Show code
#If the value of VIF is less than 1: no correlation - If the value of VIF is between 1-5, there is moderate correlation - If the value of VIF is above 5: severe correlation 

#_#_#_#_#_#_#_#_#_
invisible("3.Cox, collinearity")
#global covs_3 "i.caus_disch_mod_imp_rec edad_al_ing_1 edad_ini_cons i.sex_enc i.esc_rec i.sus_prin_mod i.fr_sus_prin i.comp_biosoc i.ten_viv i.dg_cie_10_rec i.sud_severity_icd10 i.macrozone i.policonsumo i.n_off_vio i.n_off_acq i.n_off_sud "

#Error in Design(data, formula, specials = c("strat", "strata")) : 
#  Variable escolaridad_rec is an ordered factor with non-numeric levels.
# You should set options(contrasts=c("contr.treatment", "contr.treatment"))
#or rms will not work properly.
options(contrasts=c("contr.treatment", "contr.treatment"))
#https://randomeffect.net/post/2021/05/02/the-rms-validate-function/
f1 <- cph(Surv(yrs_to_tr_dropout, event) ~ con_quien_vive_joel + edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, data= prueba2_imp2, x=T, y=T)
#warning("X matrix deemed to be singular; variable n_off_oth")

cvif <- rms::vif(f1)


cvif%>% 
  knitr::kable("markdown", caption= "Variance Inflation Factors in Cox Regressions")
Table 10: Variance Inflation Factors in Cox Regressions
x
con_quien_vive_joel=Family of origin 5.062774
con_quien_vive_joel=With couple/children 4.815530
edad_al_ing 1.185765
sexo_2=Women 1.279537
escolaridad_rec=2-Completed high school or less 1.390392
escolaridad_rec=1-More than high school 1.446157
sus_ini_mod_mvv=Cocaine hydrochloride 1.116117
sus_ini_mod_mvv=Marijuana 1.308500
sus_ini_mod_mvv=Other 1.066281
sus_ini_mod_mvv=Cocaine paste 1.149405
freq_cons_sus_prin=2 to 3 days a week 3.982403
freq_cons_sus_prin=4 to 6 days a week 3.152015
freq_cons_sus_prin=Daily 4.767005
freq_cons_sus_prin=Less than 1 day a week 1.663196
via_adm_sus_prin_act=Intranasal (powder aspiration) 23.948588
via_adm_sus_prin_act=Injected Intravenously or Intramuscularly 1.093445
via_adm_sus_prin_act=Oral (drunk or eaten) 22.726709
via_adm_sus_prin_act=Other 1.009243
condicion_ocupacional_corr=Inactive 1.255954
condicion_ocupacional_corr=Looking for a job for the first time 1.011687
condicion_ocupacional_corr=No activity 1.152128
condicion_ocupacional_corr=Not seeking for work 1.029332
condicion_ocupacional_corr=Unemployed 1.397809
compromiso_biopsicosocial=2-Moderate 3.358003
compromiso_biopsicosocial=3-Severe 4.075207
numero_de_hijos_mod_joel=1 1.435555
numero_de_hijos_mod_joel=2 1.496315
numero_de_hijos_mod_joel=3 1.241426
numero_de_hijos_mod_joel=4 or more 1.137270
tipo_de_plan_2_mod=PAI 1.490520
tipo_de_plan_2_mod=PR 1.935490
tenencia_de_la_vivienda_mod=Others 3.351341
tenencia_de_la_vivienda_mod=Owner/Transferred dwellings/Pays Dividends 22.357871
tenencia_de_la_vivienda_mod=Renting 14.819127
tenencia_de_la_vivienda_mod=Stays temporarily with a relative 25.766616
tipo_centro=Public 1.387114
cnt_mod_cie_10_dg_cons_sus_or 1.801449
sus_principal_mod=Cocaine hydrochloride 50.324496
sus_principal_mod=Marijuana 17.214365
sus_principal_mod=Other 1.210444
sus_principal_mod=Cocaine paste 41.689593
macrozona=North 1.183885
macrozona=South 1.107565
cnt_mod_cie_10_or 1.637842
cnt_mod_cie_10_or=2 1.125584
cnt_mod_cie_10_or=3 1.037060
Show code
    # dplyr::mutate_if(is.numeric,~round(.,2)) %>% 
    # DT::datatable()

Time for this code chunk to run: 0 minutes

Adjusted

We calculated the restricted mean survival time and lost, considering that proportionality of trends could be violated.

Show code
#(3) (PDF) Adjusted restricted mean survival times in observational studies. Available from: https://www.researchgate.net/publication/333326572_Adjusted_restricted_mean_survival_times_in_observational_studies [accessed Feb 02 2023].

logit <- glm (con_quien_vive_joel_fam_or ~ edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, 
              data=prueba2_imp2, family=binomial(link= "logit"))

pred <- predict(logit, type="response")
prueba2_imp2$weight <- prueba2_imp2$con_quien_vive_joel_fam_or/pred + (1 - prueba2_imp2$con_quien_vive_joel_fam_or)/(1-pred)

#https://anthonyongphd.files.wordpress.com/2016/02/emerging-adulthood-2016-thoemmes-40-59.pdf
#A Primer on Inverse Probability of Treatment Weighting and Marginal Structural Models
#truncate weights at 1%
prueba2_imp2$weight_tr <- ifelse(prueba2_imp2$weight < quantile(prueba2_imp2$weight, probs=.01), quantile(prueba2_imp2$weight, probs=.01), prueba2_imp2$weight)
prueba2_imp2$weight_tr <- ifelse(prueba2_imp2$weight > quantile(prueba2_imp2$weight, probs=.99), quantile(prueba2_imp2$weight, probs=.99), prueba2_imp2$weight_tr)

#truncate weights at 5%
prueba2_imp2$weight_tr2 <- ifelse(prueba2_imp2$weight < quantile(prueba2_imp2$weight, probs=.05), quantile(prueba2_imp2$weight, probs=.05), prueba2_imp2$weight)
prueba2_imp2$weight_tr2 <- ifelse(prueba2_imp2$weight > quantile(prueba2_imp2$weight, probs=.95), quantile(prueba2_imp2$weight, probs=.95), prueba2_imp2$weight_tr2)

#truncate weights at 5%
prueba2_imp2$weight_tr3 <- ifelse(prueba2_imp2$weight < quantile(prueba2_imp2$weight, probs=.1), quantile(prueba2_imp2$weight, probs=.1), prueba2_imp2$weight)
prueba2_imp2$weight_tr3 <- ifelse(prueba2_imp2$weight > quantile(prueba2_imp2$weight, probs=.9), quantile(prueba2_imp2$weight, probs=.9), prueba2_imp2$weight_tr3)


cat("===============================================================================")
===============================================================================
Show code
logit2 <- glm (con_quien_vive_joel_alone ~ edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, 
              data=prueba2_imp2, family=binomial(link= "logit"))

pred2 <- predict(logit2, type="response")
prueba2_imp2$weight_a <- prueba2_imp2$con_quien_vive_joel_alone/pred2 + (1 - prueba2_imp2$con_quien_vive_joel_alone)/(1-pred2)

#https://anthonyongphd.files.wordpress.com/2016/02/emerging-adulthood-2016-thoemmes-40-59.pdf
#A Primer on Inverse Probability of Treatment Weighting and Marginal Structural Models
#truncate weights at 1%
prueba2_imp2$weight_tr_a <- ifelse(prueba2_imp2$weight_a < quantile(prueba2_imp2$weight_a, probs=.01), quantile(prueba2_imp2$weight_a, probs=.01), prueba2_imp2$weight_a)
prueba2_imp2$weight_tr_a <- ifelse(prueba2_imp2$weight_a > quantile(prueba2_imp2$weight_a, probs=.99), quantile(prueba2_imp2$weight_a, probs=.99), prueba2_imp2$weight_tr_a)

#truncate weights at 5%
prueba2_imp2$weight_tr2_a <- ifelse(prueba2_imp2$weight_a < quantile(prueba2_imp2$weight_a, probs=.05), quantile(prueba2_imp2$weight, probs=.05), prueba2_imp2$weight)
prueba2_imp2$weight_tr2_a <- ifelse(prueba2_imp2$weight_a > quantile(prueba2_imp2$weight_a, probs=.95), quantile(prueba2_imp2$weight_a, probs=.95), prueba2_imp2$weight_tr2_a)

#truncate weights at 5%
prueba2_imp2$weight_tr3_a <- ifelse(prueba2_imp2$weight_a < quantile(prueba2_imp2$weight_a, probs=.1), quantile(prueba2_imp2$weight_a, probs=.1), prueba2_imp2$weight_a)
prueba2_imp2$weight_tr3_a <- ifelse(prueba2_imp2$weight_a > quantile(prueba2_imp2$weight_a, probs=.9), quantile(prueba2_imp2$weight_a, probs=.9), prueba2_imp2$weight_tr3_a)


cat("===============================================================================")
===============================================================================
Show code
logit3 <- glm (con_quien_vive_joel_coup_chil ~ edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, 
              data=prueba2_imp2, family=binomial(link= "logit"))

pred3 <- predict(logit3, type="response")
prueba2_imp2$weight_b <- prueba2_imp2$con_quien_vive_joel_coup_chil/pred + (1 - prueba2_imp2$con_quien_vive_joel_coup_chil)/(1-pred)

#https://anthonyongphd.files.wordpress.com/2016/02/emerging-adulthood-2016-thoemmes-40-59.pdf
#A Primer on Inverse Probability of Treatment Weighting and Marginal Structural Models
#truncate weights at 1%
prueba2_imp2$weight_tr_b <- ifelse(prueba2_imp2$weight_b < quantile(prueba2_imp2$weight_b, probs=.01), quantile(prueba2_imp2$weight_b, probs=.01), prueba2_imp2$weight_b)
prueba2_imp2$weight_tr_b <- ifelse(prueba2_imp2$weight_b > quantile(prueba2_imp2$weight_b, probs=.99), quantile(prueba2_imp2$weight_b, probs=.99), prueba2_imp2$weight_tr_b)

#truncate weights at 5%
prueba2_imp2$weight_tr2_b <- ifelse(prueba2_imp2$weight_b < quantile(prueba2_imp2$weight_b, probs=.05), quantile(prueba2_imp2$weight_b, probs=.05), prueba2_imp2$weight_b)
prueba2_imp2$weight_tr2_b <- ifelse(prueba2_imp2$weight_b > quantile(prueba2_imp2$weight_b, probs=.95), quantile(prueba2_imp2$weight_b, probs=.95), prueba2_imp2$weight_tr2_b)

#truncate weights at 5%
prueba2_imp2$weight_tr3_b <- ifelse(prueba2_imp2$weight_b < quantile(prueba2_imp2$weight_b, probs=.1), quantile(prueba2_imp2$weight_b, probs=.1), prueba2_imp2$weight_b)
prueba2_imp2$weight_tr3_b <- ifelse(prueba2_imp2$weight_b > quantile(prueba2_imp2$weight_b, probs=.9), quantile(prueba2_imp2$weight_b, probs=.9), prueba2_imp2$weight_tr3_b)

# AKM RMST adjusted for age
source("https://raw.githubusercontent.com/s-conner/akm-rmst/master/AKM_rmst.R")

cat("===============================================================================")
===============================================================================
Show code
cat("Living with Family of origin(1) vs. Alone and With couple/children at 1 year (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.571 0.005
Group 1   0.593 0.003


Restricted Mean Survival Time (RMST) Differences 

                  Est.    SE   CIL   CIU p
Groups 1 vs. 0   0.023 0.006 0.011 0.035 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.   SE Est.   CIL   CIU p
Groups 1 vs. 0      0.039 0.01 1.04 1.019 1.062 0
Show code
cat("Living with Family of origin(1) vs. Alone and With couple/children at 3 years (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.141 0.017
Group 1   1.220 0.012


Restricted Mean Survival Time (RMST) Differences 

                  Est.    SE   CIL  CIU p
Groups 1 vs. 0   0.079 0.021 0.038 0.12 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0      0.067 0.018 1.069 1.032 1.108 0
Show code
cat("Living with Family of origin(1) vs. Alone and With couple/children at 5 years (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.694 0.030
Group 1   1.822 0.021


Restricted Mean Survival Time (RMST) Differences 

                  Est.    SE   CIL CIU p
Groups 1 vs. 0   0.129 0.037 0.057 0.2 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0      0.073 0.021 1.076 1.032 1.121 0.001
Show code
cat("===============================================================================")
===============================================================================
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 1 year (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr_a, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.592 0.002
Group 1   0.560 0.013


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU     p
Groups 1 vs. 0   -0.032 0.013 -0.058 -0.006 0.015


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL  CIU     p
Groups 1 vs. 0     -0.056 0.024 0.945 0.903 0.99 0.017
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 3 years (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr_a, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.209 0.008
Group 1   1.131 0.044


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL  CIU     p
Groups 1 vs. 0   -0.078 0.045 -0.167 0.01 0.082


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.   SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.067 0.04 0.935 0.865 1.011 0.092
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 5 years (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr_a, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.804 0.014
Group 1   1.689 0.077


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE   CIL   CIU     p
Groups 1 vs. 0   -0.115 0.079 -0.27 0.039 0.143


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.066 0.047 0.936 0.855 1.026 0.156
Show code
cat("===============================================================================")
===============================================================================
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 1 year (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr_b, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.605 0.004
Group 1   0.589 0.006


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE   CIL    CIU     p
Groups 1 vs. 0   -0.016 0.007 -0.03 -0.003 0.017


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.027 0.012 0.973 0.951 0.995 0.018
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 3 years (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr_b, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.296 0.013
Group 1   1.144 0.020


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU p
Groups 1 vs. 0   -0.152 0.024 -0.199 -0.105 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.   SE  Est.   CIL   CIU p
Groups 1 vs. 0     -0.125 0.02 0.883 0.848 0.918 0
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 5 years (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr_b, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.965 0.023
Group 1   1.674 0.035


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU p
Groups 1 vs. 0   -0.291 0.042 -0.373 -0.209 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0      -0.16 0.024 0.852 0.813 0.893 0

Time for this code chunk to run: 0.2 minutes

We assess the covariates’ balance after the weighting

Show code
bal_tab<-
cobalt::bal.tab(event ~ con_quien_vive_joel_fam_or+ edad_al_ing+ sexo_2 + escolaridad_rec + sus_ini_mod_mvv + freq_cons_sus_prin + via_adm_sus_prin_act + condicion_ocupacional_corr+ compromiso_biopsicosocial + numero_de_hijos_mod_joel + tipo_de_plan_2_mod+ tenencia_de_la_vivienda_mod + tipo_centro+ cnt_mod_cie_10_dg_cons_sus_or + sus_principal_mod+ macrozona + cnt_mod_cie_10_or, data = prueba2_imp2,
                weights = c("weight","weight_tr", "weight_tr2", "weight_tr3"),
                estimand = "ATT",
                un = T, 
                 binary = "std", continuous = "std",
                stats = c("mean.diffs", "variance.ratios"))

bal_tab$Balance %>% 
  dplyr::mutate_if(is.numeric, ~round(.,2)) %>% 
  knitr::kable("markdown", caption="Balance Measures")
Table 11: Balance Measures
Type Diff.Un V.Ratio.Un Diff.weight V.Ratio.weight Diff.weight_tr V.Ratio.weight_tr Diff.weight_tr2 V.Ratio.weight_tr2 Diff.weight_tr3 V.Ratio.weight_tr3
con_quien_vive_joel_fam_or Binary -0.09 -0.06 -0.06 -0.07 -0.08
edad_al_ing Contin. 0.00 0.94 -0.02 0.96 -0.02 0.96 -0.02 0.96 -0.02 0.95
sexo_2_Women Binary -0.08 -0.10 -0.09 -0.09 -0.09
escolaridad_rec_3-Completed primary school or less Binary 0.15 0.16 0.16 0.16 0.15
escolaridad_rec_2-Completed high school or less Binary 0.01 0.02 0.01 0.01 0.00
escolaridad_rec_1-More than high school Binary -0.21 -0.23 -0.22 -0.21 -0.20
sus_ini_mod_mvv_Alcohol Binary -0.09 -0.09 -0.09 -0.09 -0.09
sus_ini_mod_mvv_Cocaine hydrochloride Binary 0.04 0.04 0.04 0.04 0.04
sus_ini_mod_mvv_Marijuana Binary 0.05 0.05 0.05 0.05 0.05
sus_ini_mod_mvv_Other Binary -0.01 -0.01 -0.01 -0.02 -0.02
sus_ini_mod_mvv_Cocaine paste Binary 0.06 0.06 0.07 0.07 0.07
freq_cons_sus_prin_1 day a week or more Binary -0.03 -0.04 -0.04 -0.03 -0.03
freq_cons_sus_prin_2 to 3 days a week Binary 0.02 0.03 0.03 0.02 0.02
freq_cons_sus_prin_4 to 6 days a week Binary 0.01 0.01 0.02 0.02 0.02
freq_cons_sus_prin_Daily Binary -0.01 -0.01 -0.02 -0.02 -0.01
freq_cons_sus_prin_Less than 1 day a week Binary -0.01 -0.01 -0.01 -0.01 -0.01
via_adm_sus_prin_act_Smoked or Pulmonary Aspiration Binary 0.11 0.13 0.12 0.12 0.12
via_adm_sus_prin_act_Intranasal (powder aspiration) Binary -0.01 -0.02 -0.02 -0.02 -0.02
via_adm_sus_prin_act_Injected Intravenously or Intramuscularly Binary -0.03 -0.03 -0.03 -0.03 -0.04
via_adm_sus_prin_act_Oral (drunk or eaten) Binary -0.13 -0.13 -0.14 -0.13 -0.14
via_adm_sus_prin_act_Other Binary -0.01 -0.02 -0.02 -0.02 -0.02
condicion_ocupacional_corr_Employed Binary 0.10 0.09 0.09 0.10 0.10
condicion_ocupacional_corr_Inactive Binary -0.09 -0.09 -0.09 -0.09 -0.09
condicion_ocupacional_corr_Looking for a job for the first time Binary -0.01 -0.01 -0.01 -0.01 -0.01
condicion_ocupacional_corr_No activity Binary -0.07 -0.02 -0.02 -0.04 -0.04
condicion_ocupacional_corr_Not seeking for work Binary -0.03 -0.01 -0.01 -0.02 -0.02
condicion_ocupacional_corr_Unemployed Binary -0.02 -0.03 -0.03 -0.03 -0.03
compromiso_biopsicosocial_1-Mild Binary -0.02 -0.02 -0.02 -0.02 -0.03
compromiso_biopsicosocial_2-Moderate Binary 0.02 0.01 0.02 0.03 0.03
compromiso_biopsicosocial_3-Severe Binary -0.01 0.00 -0.01 -0.01 -0.01
numero_de_hijos_mod_joel_0 Binary -0.14 -0.11 -0.11 -0.11 -0.12
numero_de_hijos_mod_joel_1 Binary 0.09 0.06 0.06 0.06 0.07
numero_de_hijos_mod_joel_2 Binary 0.05 0.05 0.05 0.05 0.05
numero_de_hijos_mod_joel_3 Binary 0.01 -0.01 -0.01 -0.01 -0.01
numero_de_hijos_mod_joel_4 or more Binary 0.05 0.05 0.05 0.05 0.05
tipo_de_plan_2_mod_PAB Binary 0.15 0.16 0.16 0.16 0.16
tipo_de_plan_2_mod_PAI Binary -0.06 -0.07 -0.06 -0.06 -0.05
tipo_de_plan_2_mod_PR Binary -0.14 -0.13 -0.14 -0.16 -0.16
tenencia_de_la_vivienda_mod_Illegal Settlement Binary 0.02 -0.01 -0.01 -0.01 0.00
tenencia_de_la_vivienda_mod_Others Binary 0.02 0.03 0.03 0.02 0.02
tenencia_de_la_vivienda_mod_Owner/Transferred dwellings/Pays Dividends Binary -0.06 -0.05 -0.05 -0.04 -0.04
tenencia_de_la_vivienda_mod_Renting Binary 0.01 -0.01 -0.02 -0.02 -0.02
tenencia_de_la_vivienda_mod_Stays temporarily with a relative Binary 0.04 0.05 0.05 0.05 0.05
tipo_centro_Public Binary 0.10 0.11 0.11 0.12 0.12
cnt_mod_cie_10_dg_cons_sus_or Contin. -0.17 0.89 -0.15 0.89 -0.16 0.89 -0.16 0.89 -0.15 0.89
sus_principal_mod_Alcohol Binary -0.12 -0.12 -0.13 -0.13 -0.13
sus_principal_mod_Cocaine hydrochloride Binary -0.01 -0.03 -0.02 -0.02 -0.02
sus_principal_mod_Marijuana Binary -0.11 -0.08 -0.09 -0.09 -0.10
sus_principal_mod_Other Binary -0.08 -0.07 -0.06 -0.06 -0.07
sus_principal_mod_Cocaine paste Binary 0.19 0.18 0.18 0.18 0.18
macrozona_Center Binary 0.15 0.14 0.14 0.15 0.15
macrozona_North Binary -0.01 -0.01 -0.01 -0.02 -0.02
macrozona_South Binary -0.23 -0.22 -0.22 -0.21 -0.22
cnt_mod_cie_10_or_0 Binary -0.06 -0.11 -0.10 -0.09 -0.09
cnt_mod_cie_10_or_1 Binary 0.08 0.13 0.13 0.11 0.10
cnt_mod_cie_10_or_2 Binary -0.07 -0.09 -0.08 -0.08 -0.07
cnt_mod_cie_10_or_3 Binary -0.04 -0.05 -0.05 -0.05 -0.04

Time for this code chunk to run: 0 minutes

Show code
bal_tab$Observations %>% 
  #dplyr::mutate_if(is.numeric, ~round(.,2)) %>% 
  knitr::kable("markdown", caption="Effective sample sizes")
Table 12: Effective sample sizes
Control Treated
All 7768.000 16211.000
weight 3788.064 8173.960
weight_tr 4324.160 9312.919
weight_tr2 5886.040 12474.737
weight_tr3 6652.756 13990.583

Time for this code chunk to run: 0 minutes

Educational attainment in “More than high school” category had great differences between groups. Also the South Macrozone showed high standardized differences, meaning that the sample could not be balanced yet. Truncating at 5% and 10% behaves better. We decided to use the most truncated weight

Show code
#(3) (PDF) Adjusted restricted mean survival times in observational studies. Available from: https://www.researchgate.net/publication/333326572_Adjusted_restricted_mean_survival_times_in_observational_studies [accessed Feb 02 2023].


# AKM RMST adjusted for age
source("https://raw.githubusercontent.com/s-conner/akm-rmst/master/AKM_rmst.R")

cat("Living with Family of origin(1) vs. Alone and With couple/children at 1 year (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr3, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.573 0.004
Group 1   0.595 0.003


Restricted Mean Survival Time (RMST) Differences 

                  Est.    SE   CIL   CIU p
Groups 1 vs. 0   0.022 0.005 0.012 0.032 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0      0.037 0.009 1.038 1.021 1.056 0
Show code
cat("Living with Family of origin(1) vs. Alone and With couple/children at 3 years (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr3, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.134 0.014
Group 1   1.223 0.011


Restricted Mean Survival Time (RMST) Differences 

                 Est.    SE   CIL   CIU p
Groups 1 vs. 0   0.09 0.017 0.056 0.124 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0      0.076 0.015 1.079 1.048 1.111 0
Show code
cat("Living with Family of origin(1) vs. Alone and With couple/children at 5 years (adjusted)")
Living with Family of origin(1) vs. Alone and With couple/children at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_fam_or),weight=prueba2_imp2$weight_tr3, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.675 0.024
Group 1   1.828 0.018


Restricted Mean Survival Time (RMST) Differences 

                  Est.   SE   CIL   CIU p
Groups 1 vs. 0   0.153 0.03 0.093 0.212 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL  CIU p
Groups 1 vs. 0      0.087 0.018 1.091 1.054 1.13 0
Show code
cat("===============================================================================")
===============================================================================
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 1 year (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr3, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.588 0.003
Group 1   0.550 0.011


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE   CIL    CIU     p
Groups 1 vs. 0   -0.038 0.011 -0.06 -0.016 0.001


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.   SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.067 0.02 0.935 0.899 0.973 0.001
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 3 years (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr3, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.187 0.009
Group 1   1.141 0.037


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE   CIL   CIU     p
Groups 1 vs. 0   -0.046 0.038 -0.12 0.028 0.226


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.039 0.033 0.962 0.901 1.026 0.234
Show code
cat("Living Alone(1) vs. with Family of origin and With couple/children at 5 years (adjusted)")
Living Alone(1) vs. with Family of origin and With couple/children at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_alone),weight=prueba2_imp2$weight_tr3, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.764 0.015
Group 1   1.720 0.064


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL   CIU     p
Groups 1 vs. 0   -0.043 0.066 -0.172 0.085 0.508


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.025 0.038 0.975 0.905 1.051 0.513
Show code
cat("===============================================================================")
===============================================================================
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 1 year (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 1 year (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr3, tau=1)




RMST calculated up to tau = 1


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   0.590 0.003
Group 1   0.577 0.004


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU     p
Groups 1 vs. 0   -0.013 0.005 -0.023 -0.002 0.016


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU     p
Groups 1 vs. 0     -0.022 0.009 0.979 0.961 0.996 0.017
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 3 years (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 3 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr3, tau=3)




RMST calculated up to tau = 3


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.214 0.010
Group 1   1.132 0.015


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU p
Groups 1 vs. 0   -0.082 0.018 -0.118 -0.047 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0      -0.07 0.016 0.932 0.904 0.961 0
Show code
cat("Living with couple/children(1) vs. Family of origin & alone at 5 years (adjusted)")
Living with couple/children(1) vs. Family of origin & alone at 5 years (adjusted)
Show code
akm_rmst(time=prueba2_imp2$yrs_to_tr_dropout, status=prueba2_imp2$event, group=as.factor(prueba2_imp2$con_quien_vive_joel_coup_chil),weight=prueba2_imp2$weight_tr3, tau=5)




RMST calculated up to tau = 5


Restricted Mean Survival Time (RMST) per Group 

           RMST    SE
Group 0   1.816 0.018
Group 1   1.667 0.026


Restricted Mean Survival Time (RMST) Differences 

                   Est.    SE    CIL    CIU p
Groups 1 vs. 0   -0.149 0.032 -0.212 -0.087 0


Restricted Mean Survival Time (RMST) Ratios 

                 Log Est.    SE  Est.   CIL   CIU p
Groups 1 vs. 0     -0.086 0.019 0.918 0.885 0.952 0

Time for this code chunk to run: 0.1 minutes


Export

Show code
vector_var_names<-c("hash_key", "edad_al_ing", "fech_ing", "fech_egres_imp", "event", "diff_bet_treat", "tipo_de_programa_2", "abandono_temprano", "motivodeegreso_mod_imp")
  
prueba2_imp2%>%
  dplyr::arrange(hash_key, edad_al_ing)%>% 
  #dplyr::left_join(prueba2[,vector_var_names], by=c("hash_key"="hash_key", "edad_al_ing"="edad_al_ing")) %>% 
  #dplyr::left_join(prueba2_imp2[,c("hash_key","edad_al_ing","duplicates_filtered_adj","person_years","max_cum_dias_trat_sin_na_adj")], by=c("hash_key"="hash_key", "edad_al_ing"="edad_al_ing")) %>% 
    rio::export(file = paste0(gsub("analisis_joel2.Rmd","",path),"CONS_C1_df_dup_SEP_2020_joel_feb_2023.dta"))

if(no_mostrar==1){
          #23,979
        missing.values2<-
            prueba2 %>%
            rowwise %>%
            dplyr::mutate_all(~ifelse(is.na(.), 1, 0)) %>% 
            dplyr::ungroup() %>% 
            dplyr::summarise_all(~sum(.))
        
        invisible("Para ver los nombres de las variables")
        for(i in 1:length(prueba)){
        print(paste0(names(prueba)[[i]],"= ",attr(prueba[[i]],"label")))
          }
}  

Time for this code chunk to run: 0 minutes


Flowchart

Show code
tab1_lab<- paste0('Original C1 Dataset \n(n = ', formatC(nrow(CONS_C1), format='f', big.mark=',', digits=0), ';\nusers: ',formatC(CONS_C1%>% dplyr::distinct(HASH_KEY)%>% nrow(), format='f', big.mark=',', digits=0),')')
tab2_lab<- paste0('C1 Dataset \n(n = ', formatC(nrow(CONS_C1_df_dup_SEP_2020), format='f', big.mark=',', digits=0), ';\nusers: ',formatC(CONS_C1_df_dup_SEP_2020%>% dplyr::distinct(hash_key)%>% nrow(), format='f', big.mark=',', digits=0),')')

tab1_5_lab_1<- paste0('(n=', CONS_C1_df_dup_SEP_2020 %>% dplyr::group_by(hash_key) %>% dplyr::mutate(menor_edad=dplyr::case_when(edad_al_ing<18~1,TRUE~0),menor_edad=sum(menor_edad,na.rm=T)) %>% dplyr::ungroup() %>% dplyr::filter(edad_al_ing<18) %>% nrow(), '; users= ',CONS_C1_df_dup_SEP_2020 %>% dplyr::group_by(hash_key) %>% dplyr::mutate(menor_edad=dplyr::case_when(edad_al_ing<18~1,TRUE~0),menor_edad=sum(menor_edad,na.rm=T)) %>% dplyr::ungroup() %>% dplyr::filter(edad_al_ing<18) %>% dplyr::distinct(hash_key)%>% nrow(), ')')
tab1_5_lab_2<- paste0('(n=', prueba%>% dplyr::filter(edad_al_ing_grupos!="18-29"|is.na(edad_al_ing_grupos)) %>% dplyr::distinct(hash_key) %>%  nrow() %>% format(big.mark=","),'; users=', prueba%>% dplyr::filter(edad_al_ing_grupos!="18-29"|is.na(edad_al_ing_grupos)) %>% nrow() %>% format(big.mark=","),')')
  
tab1_5_lab<- paste0('&#8226; Discarded cases with no age at admission or ages below 18 years old ',  tab1_5_lab_1,'\\\\\\l&#8226; Discarded ages different than between 18-29 years old at admission ',tab1_5_lab_2,'\\\\\\l')

tab4_lab<- paste0('C1 Dataset on Young Adults \n(n = ',format(nrow(prueba2), big.mark=","),')')#, formatC(nrow(CONS_C1_df_dup_SEP_2020_match_miss_after_imp_conservados), format='f', big.mark=',', digits=0), ';\nusers: ',formatC(CONS_C1_df_dup_SEP_2020_match_miss_after_imp_conservados%>% dplyr::distinct(hash_key)%>% nrow(), format='f', big.mark=',', digits=0),')')

tab3_5_lab<- paste0('C1 Dataset \n(n = ')#, formatC(nrow(CONS_C1_df_dup_SEP_2020_match_miss_after_imp_descartados), format='f', big.mark=',', digits=0), ';\nusers: ',formatC(CONS_C1_df_dup_SEP_2020_match_miss_after_imp_descartados%>% dplyr::distinct(hash_key)%>% nrow(), format='f', big.mark=',', digits=0),')')

tab5_lab<- paste0('&#8226; Imputed values of users with at least 1 missing value (n= ',prueba2 %>%
  rowwise %>% dplyr::mutate_at(.vars = vars(vector_variables),.funs = ~ifelse(is.na(.), 1, 0)) %>% 
  dplyr::ungroup() %>% dplyr::select(any_of(vector_variables)) %>% dplyr::mutate(total_na=rowSums(., na.rm=T)) %>% dplyr::filter(total_na>0) %>% nrow() %>% format(big.mark=","),'; ', round(prueba2 %>%
  rowwise %>% dplyr::mutate_at(.vars = vars(vector_variables),.funs = ~ifelse(is.na(.), 1, 0)) %>% 
  dplyr::ungroup() %>% dplyr::select(any_of(vector_variables)) %>% dplyr::mutate(total_na=rowSums(., na.rm=T)) %>% dplyr::filter(total_na>0) %>% nrow()/nrow(prueba2),2)*100 ,'%)\\\\\\l&#8226; Substance use onset age and Initial substance were the variables with more missing values and had ', round(parse_number(data.frame(miss_val_bar)[1,3]),0),'% each one \\\\\\l')


lab_tab<- paste0("  Result of the\nimputed dataset\n(n= ",format(nrow(prueba2_imp2),big.mark=","),")")#,table(table(t_id_1)) %>% formatC(big.mark = ","),"; No. of controls: ",table(table(c_id_1))%>% formatC(big.mark = ","))

#https://stackoverflow.com/questions/46750364/diagrammer-and-graphviz
#https://mikeyharper.uk/flowcharts-in-r-using-diagrammer/
#http://blog.nguyenvq.com/blog/2012/05/29/better-decision-tree-graphics-for-rpart-via-party-and-partykit/
#http://blog.nguyenvq.com/blog/2014/01/17/skeleton-to-create-fast-automatic-tree-diagrams-using-r-and-graphviz/
#https://cran.r-project.org/web/packages/DiagrammeR/vignettes/graphviz-mermaid.html
#https://stackoverflow.com/questions/39133058/how-to-use-graphviz-graphs-in-diagrammer-for-r
#https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781789802566/1/ch01lvl1sec21/creating-diagrams-via-the-diagrammer-package
#https://justlegal.be/2019/05/using-flowcharts-to-display-legal-procedures/
# paste0("No. of treatments: ",table(table(t_id_1)) %>% formatC(big.mark = ","),"; No. of controls: ",table(table(c_id_1))%>% formatC(big.mark = ","))
#
library(DiagrammeR) #⋉
flowchrt_p1<-
grViz([1468 chars quoted with '"'], width = 1200,
        height = 900)

DPI = 1200
WidthCM = 11
HeightCM = 8

flowchrt_p1
Show code
flowchrt_p1 %>%
  export_svg %>% charToRaw %>% rsvg_pdf("_flowchart_joel.pdf")
flowchrt_p1 %>% export_svg()%>%charToRaw %>% rsvg(width = WidthCM *(DPI/2.54), height = HeightCM *(DPI/2.54)) %>% png::writePNG("_flowchart_joel.png")

htmlwidgets::saveWidget(flowchrt_p1, "_flowchart_joel.html")
webshot::webshot("_flowchart_joel.html", "_flowchart_joel_corr.png",vwidth = 1200, vheight = 900, zoom = 3)

Time for this code chunk to run: 0 minutes


Session Info

Show code
Sys.getenv("R_LIBS_USER")
[1] "C:/Users/CISS Fondecyt/OneDrive/Documentos/R/win-library/4.0"
Show code
rstudioapi::getSourceEditorContext()
Document Context: 
- id:        'EA3D206D'
- path:      'C:/Users/CISS Fondecyt/Mi unidad/Alvacast/SISTRAT 2019 (github)/analisis_joel2.Rmd'
- contents:  <2274 rows>
Document Selection:
- [2215, 14] -- [2215, 14]: ''
Show code
save.image("__analisis_joel.RData")

unlink("*_cache", recursive = T, force = T, expand = TRUE)

sesion_info <- devtools::session_info()
dplyr::select(
  tibble::as_tibble(sesion_info$packages),
  c(package, loadedversion, source)
) %>% 
  DT::datatable(filter = 'top', colnames = c('Row number' =1,'Variable' = 2, 'Percentage'= 3),
              caption = htmltools::tags$caption(
        style = 'caption-side: top; text-align: left;',
        '', htmltools::em('Paquetes estadísticos utilizados')),
      options=list(
initComplete = htmlwidgets::JS(
      "function(settings, json) {",
      "$(this.api().tables().body()).css({'font-size': '80%'});",
      "}")))

Time for this code chunk to run: 0.1 minutes